From 80d9a32bbcdad89128b6cab1c310d7190d2d4cff Mon Sep 17 00:00:00 2001 From: Jan Konopka Date: Tue, 27 Dec 2022 20:20:51 +0100 Subject: [PATCH] feat: add null move pruning (8.7s -> 3.4s) (2.5x speedup) --- README.md | 18 ++++++++++++++++++ jangine.cpp | 46 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 26af31d..9b67840 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,12 @@ Build: g++ -Ofast jangine.cpp -o jangine +Build on Linux for Windows: + + sudo apt install mingw-w64 + x86_64-w64-mingw32-g++ -Wall -c -g -Ofast jangine.cpp -o jangine.o + x86_64-w64-mingw32-g++ -static -static-libgcc -static-libstdc++ -o jangine.exe jangine.o + Run the included test suites: # Validate move generation using move path enumeration ("perft") @@ -90,3 +96,15 @@ Run as an interactive (stdin/stdout) UCI engine: To host bot for lichess, clone the lichess-bot project https://github.com/ShailChoksi/lichess-bot and place the engine binary in the `engines/` folder. + + +## Versions + +| Version | vs previous | est. CCRL | = 1 && adaptive >= 3) + { + PiecePlusCatling ppc = make_null_move(); + ValuePlusMove rec = negamax(COLOR == WHITE ? BLACK : WHITE, -beta, -beta + 1, adaptive - 3, is_quies, false, depth + 1, lines, lines_accurate); + unmake_null_move(ppc.c_rights_w, ppc.c_rights_b); + + if (-rec.value >= beta) + return {beta, {0}}; + } + num alpha_orig = alpha; Move mv = {0}; PiecePlusCatling ppc; @@ -1027,7 +1059,7 @@ ValuePlusMove negamax(num COLOR, num alpha, num beta, num adaptive, bool is_quie rec = negamax( COLOR == WHITE ? BLACK : WHITE, -beta, -alpha, - adaptive_new, is_quies, depth + 1, lines, lines_accurate + adaptive_new, is_quies, can_null_move, depth + 1, lines, lines_accurate ); else { // https://www.chessprogramming.org/Principal_Variation_Search @@ -1036,13 +1068,13 @@ ValuePlusMove negamax(num COLOR, num alpha, num beta, num adaptive, bool is_quie rec = negamax( // try a null-window search that saves time if everything is below alpha COLOR == WHITE ? BLACK : WHITE, -(alpha+1), -alpha, - adaptive_new, is_quies, depth + 1, lines, lines_accurate + adaptive_new, is_quies, can_null_move, depth + 1, lines, lines_accurate ); if ((-rec.value) > alpha) // costly re-search if above search fails rec = negamax( COLOR == WHITE ? BLACK : WHITE, -beta, -alpha, - adaptive_new, is_quies, depth + 1, lines, lines_accurate + adaptive_new, is_quies, can_null_move, depth + 1, lines, lines_accurate ); } @@ -1172,7 +1204,7 @@ std::string calc_move(bool lines = false) SEARCH_ADAPTIVE_DEPTH = search_depth; LASTMOVE = LASTMOVE_GAME; - ValuePlusMove best_at_depth = negamax(my_color, -inf/2, inf/2, SEARCH_ADAPTIVE_DEPTH, false, 0, (DEBUG >= 2), (DEBUG >= 2)); + ValuePlusMove best_at_depth = negamax(my_color, -inf/2, inf/2, SEARCH_ADAPTIVE_DEPTH, false, true, 0, (DEBUG >= 2), (DEBUG >= 2)); printf_move(best_at_depth.move); printf_move_eval(best_at_depth, true);