vector<Move> AgentPNS::get_pv() const { vector<Move> pv; const Node * n = & root; char turn = rootboard.toplay(); while(n && !n->children.empty()){ Move m = return_move(n, turn); pv.push_back(m); n = find_child(n, m); turn = 3 - turn; } if(pv.size() == 0) pv.push_back(Move(M_RESIGN)); return pv; }
vector<Move> Player::get_pv(){ vector<Move> pv; Node * r, * n = & root; char turn = rootboard.toplay(); while(!n->children.empty()){ r = return_move(n, turn); if(!r) break; pv.push_back(r->move); turn = 3 - turn; n = r; } if(pv.size() == 0) pv.push_back(Move(M_RESIGN)); return pv; }
Player::Node * Player::genmove(double time, int max_runs, bool flexible){ time_used = 0; int toplay = rootboard.toplay(); if(rootboard.won() >= 0 || (time <= 0 && max_runs == 0)) return NULL; Time starttime; stop_threads(); if(runs) logerr("Pondered " + to_str(runs) + " runs\n"); runs = 0; maxruns = max_runs; for(unsigned int i = 0; i < threads.size(); i++) threads[i]->reset(); // if the move is forced and the time can be added to the clock, don't bother running at all if(!flexible || root.children.num() != 1){ //let them run! start_threads(); Alarm timer; if(time > 0) timer(time - (Time() - starttime), std::bind(&Player::timedout, this)); //wait for the timer to stop them runbarrier.wait(); CAS(threadstate, Thread_Wait_End, Thread_Wait_Start); assert(threadstate == Thread_Wait_Start); } if(ponder && root.outcome < 0) start_threads(); time_used = Time() - starttime; //return the best one return return_move(& root, toplay); }