From 6a7173211baa02a6fe33556a440275fe6f8c0d6e Mon Sep 17 00:00:00 2001 From: Calcitem Date: Wed, 8 Sep 2021 20:55:33 +0800 Subject: [PATCH] ai: Fix #100: Update alpha when searching When MTD(f) is disabled, played 1000 games, Win Rate: New Vs. Old 25.7% : 17.1% : 57.2% Old Vs. New 12.9% : 28.3% : 58.8% When MTD(f) is enabled, played 250 games, Win Rate: New Vs. Old 28.4% : 14.8% : 56.8% Old Vs. New 10.8% : 32.0% : 57.2% --- src/search.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 182086b2..1cb04ebd 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -244,6 +244,8 @@ Value qsearch(Position *pos, Sanmill::Stack &ss, Depth depth, Depth or Move ttMove = MOVE_NONE; #endif // TT_MOVE_ENABLE + // Transposition table lookup + #if defined (TRANSPOSITION_TABLE_ENABLE) || defined(ENDGAME_LEARNING) const Key posKey = pos->key(); #endif @@ -275,7 +277,7 @@ Value qsearch(Position *pos, Sanmill::Stack &ss, Depth depth, Depth or // check transposition-table - const Value oldAlpha = alpha; + const Value oldAlpha = alpha; // To flag BOUND_EXACT when eval above alpha and no available moves Bound type = BOUND_NONE; @@ -331,8 +333,8 @@ Value qsearch(Position *pos, Sanmill::Stack &ss, Depth depth, Depth or } #endif // THREEFOLD_REPETITION - // recurse - + // Initialize a MovePicker object for the current position, and prepare + // to search the moves. MovePicker mp(*pos); Move nextMove = mp.next_move(); const int moveCount = mp.move_count(); @@ -369,10 +371,13 @@ Value qsearch(Position *pos, Sanmill::Stack &ss, Depth depth, Depth or #endif // !DISABLE_PREFETCH #endif // TRANSPOSITION_TABLE_ENABLE + // Loop through the moves until no moves remain or a beta cutoff occurs for (int i = 0; i < moveCount; i++) { ss.push(*(pos)); const Color before = pos->sideToMove; Move move = mp.moves[i].move; + + // Make and search the move pos->do_move(move); const Color after = pos->sideToMove; @@ -435,7 +440,12 @@ Value qsearch(Position *pos, Sanmill::Stack &ss, Depth depth, Depth or bestMove = move; } - break; + if (value < beta) // Update alpha! Always alpha < beta + alpha = value; + else { + assert(value >= beta); // Fail high + break; // Fail high + } } } }