From c811dab30421c9ad635a8b13a22600e7caa5229d Mon Sep 17 00:00:00 2001 From: Tilps Date: Fri, 4 May 2018 20:47:54 +1000 Subject: [PATCH 1/4] Fix play_one_game self-play logic. It was spinning on resign, if the 450th ply was a win/loss/draw it wasn't recognized, and if the 450th ply was a win/loss/draw it was trying to play a move from that position. --- src/UCI.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/UCI.cpp b/src/UCI.cpp index 85975ca14..f79b4e2bd 100644 --- a/src/UCI.cpp +++ b/src/UCI.cpp @@ -142,10 +142,22 @@ namespace { myprintf_so("%s", options.str().c_str()); } - // Return the score from the self-play game + // Return the score from the self-play game. + // Precondition: bh.cur() is not a terminal position. int play_one_game(BoardHistory& bh) { auto search = std::make_unique(bh.shallow_clone()); for (int game_ply = 0; game_ply < 450; ++game_ply) { + Limits.startTime = now(); + Move move = search->think(bh.shallow_clone()); + + if (move != MOVE_NONE) { + myprintf_so("move played %s\n", UCI::move(move).c_str()); + bh.do_move(move); + } else { + // Resign - so whoever is current, has lost. + return bh.cur().side_to_move() == WHITE ? -1 : 1; + } + // Check if new position is terminal. if (bh.cur().is_draw()) { return 0; } @@ -159,19 +171,6 @@ namespace { return 0; } } - Limits.startTime = now(); - Move move = search->think(bh.shallow_clone()); - - myprintf_so("move played %s\n", UCI::move(move).c_str()); - bh.do_move(move); - } - Limits.startTime = now(); - Move move = search->think(bh.shallow_clone()); - if(move != MOVE_NONE) { - myprintf_so("move played %s\n", UCI::move(move).c_str()); - bh.do_move(move); - } else { - return bh.cur().side_to_move() == WHITE ? -1 : 1; } // Game termination as draw From 26e5e4d8210b3347b59b488273a0692664ae1b01 Mon Sep 17 00:00:00 2001 From: Tilps Date: Sat, 5 May 2018 10:37:11 +1000 Subject: [PATCH 2/4] Disable tree reuse in training. Doesn't seem to have a significant performance win, and has detrimental effects on the effectiveness of noise. --- src/UCI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UCI.cpp b/src/UCI.cpp index f79b4e2bd..8ea9ba236 100644 --- a/src/UCI.cpp +++ b/src/UCI.cpp @@ -145,8 +145,8 @@ namespace { // Return the score from the self-play game. // Precondition: bh.cur() is not a terminal position. int play_one_game(BoardHistory& bh) { - auto search = std::make_unique(bh.shallow_clone()); for (int game_ply = 0; game_ply < 450; ++game_ply) { + auto search = std::make_unique(bh.shallow_clone()); Limits.startTime = now(); Move move = search->think(bh.shallow_clone()); From 40ae31088806391a9f0bedb3cf1b225651f22ae2 Mon Sep 17 00:00:00 2001 From: Tilps Date: Sat, 5 May 2018 10:37:11 +1000 Subject: [PATCH 3/4] Disable tree reuse in training. Doesn't seem to have a significant performance win, and has detrimental effects on the effectiveness of noise. --- src/UCI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UCI.cpp b/src/UCI.cpp index 273c635be..d978220d7 100644 --- a/src/UCI.cpp +++ b/src/UCI.cpp @@ -145,8 +145,8 @@ namespace { // Return the score from the self-play game. // Precondition: bh.cur() is not a terminal position. int play_one_game(BoardHistory& bh) { - auto search = std::make_unique(bh.shallow_clone()); for (int game_ply = 0; game_ply < 450; ++game_ply) { + auto search = std::make_unique(bh.shallow_clone()); Limits.startTime = now(); Move move = search->think(bh.shallow_clone()); From 9461dec6d3d6a7f1adfeab94af12048a44c17a7c Mon Sep 17 00:00:00 2001 From: Tilps Date: Sat, 5 May 2018 18:03:23 +1000 Subject: [PATCH 4/4] Add a comment. --- src/UCI.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/UCI.cpp b/src/UCI.cpp index d978220d7..685eb108a 100644 --- a/src/UCI.cpp +++ b/src/UCI.cpp @@ -146,6 +146,8 @@ namespace { // Precondition: bh.cur() is not a terminal position. int play_one_game(BoardHistory& bh) { for (int game_ply = 0; game_ply < 450; ++game_ply) { + // Construct search inside the loop to ensure there is no tree reuse + // which reduces the effectiveness of noise. auto search = std::make_unique(bh.shallow_clone()); Limits.startTime = now(); Move move = search->think(bh.shallow_clone());