Skip to content

Commit

Permalink
Fix a bug (failure to collect positions) of nonslack mode that preven…
Browse files Browse the repository at this point in the history
…ts komi from adjusting back to target-komi.
  • Loading branch information
alreadydone committed Aug 26, 2018
1 parent c125528 commit 2e00b23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/UCTSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,24 @@ void UCTSearch::increment_playouts(float eval) {
}
}

bool UCTSearch::wr_out_of_range() {
if (m_root->get_visits() == 0) {
return false;
}
auto white_eval = m_root->get_raw_eval(FastBoard::WHITE);
return white_eval < cfg_min_wr
|| (white_eval > cfg_max_wr
&& (cfg_nonslack
|| m_rootstate.m_stm_komi != cfg_target_komi
|| m_rootstate.m_opp_komi != cfg_target_komi))
|| (cfg_nonslack
&& (m_rootstate.m_stm_komi < cfg_target_komi || m_rootstate.m_opp_komi < cfg_target_komi)
&& white_eval < cfg_max_wr - cfg_wr_margin)
|| (cfg_nonslack
&& (m_rootstate.m_stm_komi > cfg_target_komi || m_rootstate.m_opp_komi > cfg_target_komi)
&& white_eval > cfg_min_wr + cfg_wr_margin);
}

int UCTSearch::think(int color, passflag_t passflag) {
// Start counting time for us
m_rootstate.start_clock(color);
Expand Down Expand Up @@ -773,11 +791,7 @@ int UCTSearch::think(int color, passflag_t passflag) {

// adjust during search
if (cfg_collect_during_search) {
if (m_root->get_visits() > 0 && (m_root->get_raw_eval(FastBoard::WHITE) < cfg_min_wr
|| (m_root->get_raw_eval(FastBoard::WHITE) > cfg_max_wr
&& (cfg_nonslack
|| m_rootstate.m_stm_komi != cfg_target_komi
|| m_rootstate.m_opp_komi != cfg_target_komi)))) {
if (wr_out_of_range()){
collecting = true;
if (num_adjustments < cfg_max_num_adjustments
&& elapsed_centis * 2.0f < time_for_move
Expand Down Expand Up @@ -858,8 +872,7 @@ int UCTSearch::think(int color, passflag_t passflag) {

void UCTSearch::ponder(bool analyzing) {
update_root();



bool to_adjust;
int num_adjustments = 0;
do { //adjust during search
Expand All @@ -884,11 +897,7 @@ void UCTSearch::ponder(bool analyzing) {
}

if (cfg_collect_during_search) {
if (m_root->get_visits() > 0 && (m_root->get_raw_eval(FastBoard::WHITE) < cfg_min_wr
|| (m_root->get_raw_eval(FastBoard::WHITE) > cfg_max_wr
&& (cfg_nonslack
|| m_rootstate.m_stm_komi != cfg_target_komi
|| m_rootstate.m_opp_komi != cfg_target_komi)))) {
if (wr_out_of_range()) {
collecting = true;
if (analyzing && num_adjustments < cfg_max_num_adjustments) {
auto adj_positions0 = std::accumulate(sym_states[0].begin(), sym_states[0].end(), 0,
Expand Down
1 change: 1 addition & 0 deletions src/UCTSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class UCTSearch {
std::numeric_limits<int>::max() / 2;

UCTSearch(GameState& g, Network & network);
bool UCTSearch::wr_out_of_range();
int think(int color, passflag_t passflag = NORMAL);
void set_playout_limit(int playouts);
void set_visit_limit(int visits);
Expand Down

0 comments on commit 2e00b23

Please sign in to comment.