From a1b23ace2517ad923dc4dc808ce01af0e802204e Mon Sep 17 00:00:00 2001 From: Tilps Date: Tue, 31 Dec 2019 18:00:02 +1100 Subject: [PATCH] Don't discard games that are in positions that are already done. (#1048) * Don't discard games that are in positions that are already done. * Minor optimization. * Minor tweak for consistency with surrounding code. --- src/selfplay/game.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/selfplay/game.cc b/src/selfplay/game.cc index aba8bce95e..95c948595b 100644 --- a/src/selfplay/game.cc +++ b/src/selfplay/game.cc @@ -206,9 +206,18 @@ void SelfPlayGame::Play(int white_threads, int black_threads, bool training, kMinimumAllowedVistsId.GetId())) { break; } - auto move_list_to_discard = GetMoves(); - move_list_to_discard.push_back(move); - options_[idx].discarded_callback(move_list_to_discard); + PositionHistory history_copy = tree_[idx]->GetPositionHistory(); + Move move_for_history = move; + if (tree_[idx]->IsBlackToMove()) { + move_for_history.Mirror(); + } + history_copy.Append(move_for_history); + // Ensure not to discard games that are already decided. + if (history_copy.ComputeGameResult() == GameResult::UNDECIDED) { + auto move_list_to_discard = GetMoves(); + move_list_to_discard.push_back(move); + options_[idx].discarded_callback(move_list_to_discard); + } search_->ResetBestMove(); } // Add best move to the tree.