亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? uct.h

?? uct算法
?? H
字號:
#ifndef _UCT_H#define _UCT_H// class Pooltemplate <class e, uint size> class Pool {public:	e* memory;	e** index;	uint   free_count;	Pool() {		memory = (e*) new char[size*sizeof(e)];		index = new e*[size];		rep (i, size) 			index[i] = memory + i;		free_count = size;	}	~Pool() {		delete [] (char*)memory;		delete [] index;	}	e* malloc() { 		assertc(pool_ac, free_count > 0);		return index[--free_count]; 	}	void free(e* p) { 		index[free_count++] = p;  	}};#define node_for_each_child(node, act_node, i) do {   \	assertc (tree_ac, node!= NULL);                         \	Node<T>* act_node;                                       \	act_node = node->first_child;                      \	while (act_node != NULL) {                              \		i;                                                    \		act_node = act_node->sibling;                         \	}                                                       \} while (false)// class Nodetemplate<uint T>class Node {	static Pool<Node, uct_max_nodes> m_pool;public:	Vertex<T> v;	int    win;	uint    count;	float value() { return float(win)/float(count); }	Node*  first_child;			// head of list of moves of particular player 	Node*  sibling;                           // NULL if last child	static void * operator new(size_t t) {		assertc(pool_ac, t == sizeof(Node));		return Node::m_pool.malloc();	}	static void operator delete(void *p) {		Node::m_pool.free((Node*)p);	}	static uint free_count() {		return Node::m_pool.free_count;	}public:	void dump() {		cerr<<v			<<","<<value()			<<","<<count			<<endl;	}	void rec_print(ostream& out, uint depth, Player pl) {		rep (d, depth) out << "  ";		out			<< to_string(pl) << " "			<< v << " "			<< value() << " "			<< "(" << count - initial_bias << ")"			<< endl;		rec_print_children (out, depth, player::other(pl));	}	void rec_print_children (ostream& out, uint depth, Player player) {		Node*  child_tab [Vertex<T>::cnt]; // rough upper bound for the number of legal move		uint     child_tab_size;		uint     best_child_idx;		float    min_visit_cnt;		child_tab_size  = 0;		best_child_idx  = 0;		min_visit_cnt   = max(print_visit_threshold_base, (count - initial_bias) * print_visit_threshold_parent);		// we want to be visited at least initial_bias times + some percentage of parent's visit_cnt		// prepare for selection sort		node_for_each_child (this, child, child_tab[child_tab_size++] = child);#define best_child child_tab [best_child_idx]		while (child_tab_size > 0) {			// find best child			rep(ii, child_tab_size) {				if (best_child->value() < child_tab[ii]->value())					best_child_idx = ii;			}			// rec call			if (best_child->count - initial_bias >= min_visit_cnt)				child_tab [best_child_idx]->rec_print (out, depth + 1, player);			else break;			// remove best			best_child = child_tab [--child_tab_size];		}#undef best_child	}	void init(Vertex<T> v) {		this->v       = v;		win         = initial_value;		count         = initial_bias;		first_child   = NULL;		sibling       = NULL;	}	void add_child(Node* new_child) { // TODO sorting?		assertc(tree_ac, new_child->sibling == NULL); 		assertc(tree_ac, new_child->first_child == NULL); 		new_child->sibling = this->first_child;		this->first_child = new_child;	}	void remove_child(Node* del_child) { // TODO inefficient		Node* act_child;		assertc(tree_ac, del_child != NULL);		if (first_child == del_child) {			first_child = first_child->sibling;			return;		}		act_child = first_child;		while (true) {			assertc (tree_ac, act_child != NULL);			if (act_child->sibling == del_child) {				act_child->sibling = act_child->sibling->sibling;				return;			}			act_child = act_child->sibling;		}	}	float UCB(float explore_coeff) { 		if(!count) return large_float;		return value() + sqrt (explore_coeff / count);	}	void update_win() {		win++; 		count++;	}	void update_loss() {		win--;		count++;	}	bool is_mature () { 		return count > mature_bias_threshold; 		//return count > initial_bias; 	}	bool no_children() {		return first_child == NULL;	}	Node* find_uct_child() {		Node* best_child;		float   best_urgency;		float   explore_coeff;		best_child     = NULL;		best_urgency   = -large_float;		explore_coeff  = log(count) * explore_rate;		node_for_each_child (this, child, {			float child_urgency = child->UCB(explore_coeff);			if (child_urgency > best_urgency) {				best_urgency  = child_urgency;				best_child    = child;			}		});		//best_child->dump();		assertc (tree_ac, best_child != NULL); // at least pass		return best_child;	}	bool remove_bad_child() {		Node* worst_child = NULL;		float worst_urgency = large_float;		float explore_coeff = log(count) * explore_rate;		node_for_each_child (this, child, {			float child_urgency = child->value();			if (child_urgency < worst_urgency) {				worst_urgency  = child_urgency;				worst_child    = child;			}		});		if(worst_child == this->first_child && worst_child->sibling == NULL) {			// this is the last one			return false;		}		this->remove_child(worst_child);		free_subtree(worst_child);		delete worst_child;		return true;	}	void free_subtree(Node<T>* parent) {		node_for_each_child(parent, child, {			free_subtree(child);			delete child;		});	}	Node* find_most_explored_child() {		Node* best_child = NULL;		float max_count = 0;		best_child     = NULL;		node_for_each_child (this, child, {			if (child->count > max_count) {				max_count     = child->count;				best_child    = child;			}		});		assertc (tree_ac, best_child != NULL);		return best_child;	}	Node* find_max_value_child () {		Node* best_child = NULL;		float max_value = -large_float;		best_child     = NULL;		node_for_each_child (this, child, {			float value = child->value();			if (value > max_value) {				max_value     = value;				best_child    = child;			}		});		assertc (tree_ac, best_child != NULL);		return best_child;	}};// class Treetemplate<uint T>class UCBTree {public:	union {		Node<T>* root;		Node<T>* history[uct_max_depth];	};	uint history_top;	uint max_top;public:	void dump(Player pl) {		root->rec_print(cerr, 0, player::other(pl));	}	UCBTree () {		root = new Node<T>;		root->init(Vertex<T>::any());		history_top = 0;		max_top = 0;	}	void history_reset() {		history_top = 0;	} 	Node<T>* act_node () {		return history[history_top];	}  	void uct_descend() {		history[history_top + 1] = act_node()->find_uct_child();		history_top++;		if(history_top > max_top) max_top = history_top;		assertc(tree_ac, act_node() != NULL);	}  	void alloc_child(Vertex<T> v) {		Node<T>* new_node = new Node<T>;		new_node->init(v);		act_node()->add_child(new_node);	}  	void delete_act_node() {		assertc(tree_ac, history_top > 0);		history[history_top-1]->remove_child(act_node());		delete act_node();		history_top--;	} 	// TODO free history (for sync with base board)	// 因為某個原因,這里的act_player的含義是顛倒的	void update_history(Player winner, Player act_player) {		int stop = (history_top + 1) % 2;		int i;		if(winner != act_player) {			for(i = history_top; i >= stop;) {				history[i--]->update_win();				history[i--]->update_loss();			}			if(stop) history[i--]->update_win();		} else {			for(i = history_top; i >= stop;) {				history[i--]->update_loss();				history[i--]->update_win();			}			if(stop) history[i--]->update_loss();		}	}};template <uint T, template<uint T> class Policy, template<uint T> class Board> class UCT {public:  	Board<T>*     base_board;	Policy<T>*    policy;	UCBTree<T>          tree[1];      // TODO tree->root should be in sync with top of base_boardpublic:	UCT(Board<T>* board, Policy<T>* policy) {		this->policy = policy;		this->base_board = board;	}	Vertex<T> genmove(Player pl) {		return Vertex<T>::pass();	}public:  	/*	 * no need	 */	void root_ensure_children_legality(Player pl) { 		// cares about superko in root (only)		// 關于superko, 參考http://www.weddslist.com/kgs/past/superko.html		tree->history_reset();		assertc(uct_ac, tree->history_top == 0);		assertc(uct_ac, tree->act_node()->first_child == NULL);		empty_v_for_each_and_pass(base_board, v, {		//	if (base_board.is_strict_legal (pl, v))			tree->alloc_child(v);		});	}	//flatten 	void do_playout(Player first_player) {		Board<T>    play_board[1]; // TODO test for perfomance + memcpy		bool was_pass[player::cnt];		Player   act_player = first_player;		Vertex<T>   v;		play_board->load(base_board);		tree->history_reset();		player_for_each (pl) 			was_pass [pl] = false; // TODO maybe there was one pass ?		do {			// 葉子節點			if (tree->act_node()->no_children()) {				// If the leaf is ready expand the tree -- add children - all potential legal v (i.e.empty)				if (tree->act_node()->is_mature()) {					// 被模擬過,則生成子節點					empty_v_for_each_and_pass(play_board, v, {						tree->alloc_child(v); 						// TODO simple ko should be handled here						// (suicides and ko recaptures, needs to be dealt with later)					});					continue;				} else {					// 否則進行模擬					// TODO assert act_plauer == board->Act_player ()					Playout<T, Policy, Board>(policy, play_board).run();					//cerr<<to_string(*play_board)<<endl;					// 更新結果					tree->update_history(play_board->winner(), act_player);					// 一次模擬對局結束					//int winner_idx = play_board->winner().get_idx ();					// result values are 1 for black, -1 for white					//tree->update_history(1 - winner_idx - winner_idx); 					break;				}			}			// 非葉子節點,選擇UCT子節點			tree->uct_descend();			v = tree->act_node()->v;			if(!play_board->play(act_player, v)) {				tree->delete_act_node();				continue; //TODO: return?			}			was_pass [act_player]  = (v == Vertex<T>::pass());			//if(play_board->both_player_pass()) break;			if (was_pass [player::black] & was_pass [player::white]) {				tree->update_history(play_board->winner(), act_player);				break;			}			act_player = play_board->act_player();		} while (true);	}	void play(Player pl, Vertex<T> v) {		if(tree->root->no_children()) return;		Node<T>* new_root = NULL;		node_for_each_child(tree->root, child, {			if(v != child->v) {				tree->root->free_subtree(child);				delete child;			} else {				new_root = child;			}		});		//assert(new_root != NULL);		if(new_root == NULL) {			new_root = new Node<T>;			new_root->init(v);		} else {			new_root->sibling = NULL;		}		delete tree->root;		tree->root = new_root;	}	Vertex<T> gen_move(Player player) {		Node<T>* best;		tree->max_top = 0;		//root_ensure_children_legality(player);		//rep(ii, uct_genmove_playout_cnt) do_playout(player);		float seconds_begin = get_seconds();		float seconds_end = 0;		const uint split_cnt = 1000;		while(true) {			if(Node<T>::free_count() < split_cnt * base_board->empty_v_cnt) {				if(!tree->root->remove_bad_child()) {					break;				}				continue;			}			rep(ii, split_cnt) do_playout(player);			seconds_end = get_seconds();			if(seconds_end - seconds_begin > time_per_move) break;			if(tree->max_top > uct_max_level) break;		}		//rep(ii, 300) do_playout(player);		//best = tree->root->find_most_explored_child();		best = tree->root->find_max_value_child();		float seconds_total = seconds_end - seconds_begin;		assertc(uct_ac, best != NULL);		tree->dump(player);		cerr<<"best:";		best->dump();		cerr<<"level:"<<tree->max_top<<endl;		cerr<<"memory free:"<<Node<T>::free_count()<<endl;		cerr<<"time:"<<seconds_total<<endl;		float bestvalue = best->value();		if(bestvalue < -resign_value) return Vertex<T>::resign();		play(player, best->v);		return best->v;	}};template<uint T>// TODO:UCG將節點狀態單獨存儲,用hash索引// TODO:節點內存不夠時,將低UCB值的節點砍去Pool<Node<T>, uct_max_nodes> Node<T>::m_pool;#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区在线视频| 久久久亚洲高清| 日本少妇一区二区| 日韩免费视频线观看| 国产乱国产乱300精品| 1024成人网色www| 色94色欧美sute亚洲线路一久 | 欧美日韩国产美| 调教+趴+乳夹+国产+精品| 精品国产青草久久久久福利| 国产精品一区三区| 亚洲制服丝袜av| 久久久久高清精品| 67194成人在线观看| 成人网在线播放| 美女被吸乳得到大胸91| 日韩一区在线播放| 久久久亚洲国产美女国产盗摄| 色综合久久88色综合天天| 国产精品夜夜嗨| 日韩av电影免费观看高清完整版| 久久精品视频一区| 日韩欧美一区二区在线视频| 色妹子一区二区| www.av亚洲| 国产不卡在线一区| 国产成人精品一区二| 国产最新精品精品你懂的| 亚洲国产综合视频在线观看| 久久久久久**毛片大全| 在线视频你懂得一区二区三区| 国产精品456| 丁香婷婷综合色啪| 国产91在线看| 懂色av噜噜一区二区三区av| 国产精品羞羞答答xxdd| 黄色日韩网站视频| 国产aⅴ综合色| 97久久超碰国产精品电影| 色狠狠色狠狠综合| 欧美日韩亚洲综合在线 | aa级大片欧美| 91蝌蚪porny九色| 欧美精品日日鲁夜夜添| 日韩女优电影在线观看| 国产日韩欧美高清| 色婷婷激情综合| 91精品视频网| 久久午夜免费电影| 亚洲人成网站精品片在线观看| 国产精品灌醉下药二区| 一区二区三区在线观看欧美| 日日夜夜精品视频天天综合网| 男女激情视频一区| 色网站国产精品| 精品久久久久久久久久久久包黑料 | 欧美一二三区在线| 久久久久久免费| 国产精品久线在线观看| 樱花影视一区二区| 国产在线一区二区| 在线一区二区三区四区| 国产色爱av资源综合区| 日本怡春院一区二区| 91女神在线视频| 久久天天做天天爱综合色| 亚洲一区在线观看视频| a级精品国产片在线观看| 久久婷婷综合激情| 老司机午夜精品| 欧美一区二区三区色| 亚洲一区二区在线免费看| caoporn国产一区二区| 国产日韩精品一区二区三区在线| 青青草97国产精品免费观看无弹窗版| www.亚洲精品| 亚洲欧洲美洲综合色网| 成人激情图片网| 亚洲男人的天堂网| 欧美视频中文字幕| 日本不卡一区二区三区高清视频| 色狠狠一区二区三区香蕉| 一区二区日韩av| 精品视频在线免费观看| 日本少妇一区二区| 欧美国产欧美亚州国产日韩mv天天看完整 | 久久精品噜噜噜成人av农村| 精品久久久久久综合日本欧美| 国产一区二区三区香蕉| 亚洲摸摸操操av| 日韩精品一区在线| 91丨九色丨尤物| 国产精品资源在线观看| 亚洲一级二级三级在线免费观看| 日韩欧美一区电影| 91片在线免费观看| 麻豆精品一区二区三区| 亚洲视频精选在线| 欧美va亚洲va| 欧美zozozo| 亚洲久草在线视频| 欧美激情一区在线| 亚洲h在线观看| 欧美bbbbb| 狠狠色丁香久久婷婷综合丁香| 国产激情一区二区三区桃花岛亚洲| 日本在线不卡视频| 国产91精品精华液一区二区三区| 高清视频一区二区| 欧美日韩精品一区二区三区蜜桃| 欧美日韩国产另类不卡| 久久精品日产第一区二区三区高清版| 中文字幕免费在线观看视频一区| 亚洲三级电影全部在线观看高清| 亚洲国产成人tv| 视频一区欧美精品| 99久久国产综合精品色伊| 欧美日韩另类一区| 中文字幕中文乱码欧美一区二区| 亚洲欧美在线另类| 国产一区二区精品久久91| 国产精品亚洲成人| 欧美天天综合网| 久久免费视频色| 亚洲黄色av一区| 精品一区二区三区免费视频| 成人午夜私人影院| 7777精品伊人久久久大香线蕉最新版| 久久众筹精品私拍模特| 亚洲精品伦理在线| 国产精品主播直播| 欧美少妇xxx| 中文字幕乱码一区二区免费| 亚洲国产精品一区二区www在线 | 亚洲一二三四区不卡| 精品在线亚洲视频| 欧美另类videos死尸| 亚洲精品国产一区二区三区四区在线 | 欧美精品aⅴ在线视频| 亚洲激情在线播放| 成人中文字幕在线| 久久久久9999亚洲精品| 日本免费新一区视频| 精品视频一区二区不卡| 欧美三级资源在线| 亚洲欧美日韩电影| 99久久精品国产网站| 久久久精品蜜桃| 国产真实乱对白精彩久久| 国产亚洲精品福利| 99视频在线观看一区三区| 国产日本欧美一区二区| 国产精品一区一区| 亚洲桃色在线一区| 欧美亚洲国产怡红院影院| 丝袜a∨在线一区二区三区不卡| 欧美一区二区三区视频| 成人一区二区三区在线观看| 国产人妖乱国产精品人妖| 不卡区在线中文字幕| 亚洲天堂福利av| 久久网站最新地址| 91国产免费观看| 国产麻豆精品久久一二三| 亚洲人123区| 精品国产免费一区二区三区四区 | www.欧美日韩| 国内精品伊人久久久久av一坑 | 成人高清免费观看| 亚洲一区二区三区视频在线| 日韩免费电影一区| 一本色道a无线码一区v| 国产一区二区美女| 亚洲不卡在线观看| 亚洲男人的天堂一区二区| 精品国产乱码久久久久久图片| 一本色道综合亚洲| 国产一区在线看| 日本午夜精品视频在线观看| 一区二区三区国产精品| 国产午夜久久久久| 精品少妇一区二区三区| 欧美精品成人一区二区三区四区| av高清不卡在线| 成人av中文字幕| 国产精品影音先锋| 国产另类ts人妖一区二区| 亚洲女同ⅹxx女同tv| 国产精品水嫩水嫩| 国产视频一区不卡| 国产精品国产馆在线真实露脸 | 一区二区三区不卡视频| 亚洲国产精品影院| 国产综合色视频| 色香蕉久久蜜桃| 欧美国产一区二区在线观看| 亚洲一区二区三区自拍| 国产一区二区免费看| 在线不卡免费欧美| 日韩一区日韩二区|