int UCTSearch(int MSQ[M_Sequence_Limit], int hn,int *wins,int *visits) { if (hn > Open_Step_Limit) { if (MSQ[hn-1] == PASS && MSQ[hn-3] == PASS) { return PASS; } } Board new_board(MSQ, hn, UCT_Komi); // 取得當前盤面資訊 if (new_board.get_LegalNum() == 0) //若沒有著手可下,則虛手 { return PASS; } root = new Node(-new_board.get_color(), 0, MSQ[hn]); // color, level, move create_Tree(root, &new_board, hn); build_Tree(root, &new_board); int result = root->get_NodesValues(wins,visits);//最佳落子點 root沒小孩為0,有為1 root->delete_Tree(); return result; }
// Calculates potential; void H2_2D_Tree::build_Tree(H2_2D_Node*& node){ if(!node->isEmpty){ if(!node->isLeaf){ assign_Siblings(node); for(unsigned short k=0;k<8;++k){ if(node->neighbor[k]!=NULL){ if(!node->neighbor[k]->isLeaf && !node->neighbor[k]->isEmpty){ assign_Cousin(node,k); } } } for(unsigned short k=0;k<4;++k) { build_Tree(node->child[k]); } } } }
H2_2D_Tree::H2_2D_Tree(const unsigned short nChebNodes, double* const charge, const vector<Point>& location, const unsigned long N, const unsigned m, bool print){ this->nChebNodes = nChebNodes; this->rank = nChebNodes*nChebNodes; this->N = N; this->m = m; this->maxLevels = 0; this->chargeTree = Map<MatrixXd>(charge, N, m);// charge should be N..N..N... this->locationTree = location; this->print = print; // Get Chebyshev nodes cNode = VectorXd(nChebNodes); get_Standard_Chebyshev_Nodes(nChebNodes,cNode); // Get Chebyshev polynomials evaluated at Chebyshev nodes TNode = MatrixXd::Zero(nChebNodes,nChebNodes); get_Standard_Chebyshev_Polynomials(nChebNodes,nChebNodes,cNode,TNode); // Gets transfer matrices get_Transfer(nChebNodes,cNode,TNode,R); nLevels = 0; get_Center_Radius(location, center, radius); // Create root root = new H2_2D_Node(0, 0); root->nNeighbor = 0; root->nInteraction = 0; root->N = N; root->center = center; root->radius = radius; root->index.setLinSpaced(N,0,N-1); if(print) std::cout << "Assigning children..." << std::endl; assign_Children(root); if(print) std::cout << "Assigned children." << std::endl; build_Tree(root); if(print) std::cout << "Maximum levels is: " << this->maxLevels << std::endl; }
int UCTSearch(int MSQ[M_Sequence_Limit], int hn, float *winrate) { if (hn > 40) { if (MSQ[hn-1] == PASS && MSQ[hn-3] == PASS) { return PASS; } } Board new_board(MSQ, hn, UCT_Komi); // 取得當前盤面資訊 if (new_board.get_LegalNum() == 0) //若沒有著手可下,則虛手 { return PASS; } root = new Node(-new_board.get_color(), 0, MSQ[hn]); // color, level, move create_Tree(root, &new_board, hn); build_Tree(root, &new_board); return get_BestMove(root); }