From e35a4000e4d196f6d0c3689323ba829e44d57ced Mon Sep 17 00:00:00 2001 From: SzilBalazs Date: Tue, 29 Aug 2023 15:22:34 +0200 Subject: [PATCH] Separate history for sides Bench: 8862183 --- src/search/history.h | 18 +++++++++--------- src/search/move_list.h | 2 +- src/search/search_thread.h | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/search/history.h b/src/search/history.h index ebaaaf8..af68523 100644 --- a/src/search/history.h +++ b/src/search/history.h @@ -25,7 +25,7 @@ namespace search { public: chess::Move killer_moves[MAX_PLY + 10][2]; chess::Move counter_moves[64][64]; - Score butterfly[64][64]; + Score main_history[2][64][64]; /** * Adds a beta-cutoff to the History. @@ -35,10 +35,10 @@ namespace search { * @param depth Search depth * @param ply Distance from root */ - void add_cutoff(chess::Move move, chess::Move last_move, Depth depth, Ply ply) { + void add_cutoff(const chess::Board &board, chess::Move move, chess::Move last_move, Depth depth, Ply ply) { update_killer_moves(move, ply); update_counter_moves(move, last_move); - update_butterfly_history(move, depth * 100); + update_history(main_history[board.get_stm()][move.get_from()][move.get_to()], depth * 100); } /** @@ -47,8 +47,8 @@ namespace search { * @param move The weak move * @param depth Search depth */ - void decrease_history(chess::Move move, Depth depth) { - update_butterfly_history(move, -depth * 100); + void decrease_history(const chess::Board &board, chess::Move move, Depth depth) { + update_history(main_history[board.get_stm()][move.get_from()][move.get_to()], -depth * 100); } /** @@ -60,7 +60,7 @@ namespace search { } for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { - butterfly[i][j] = 0; + main_history[0][i][j] = main_history[1][i][j] = 0; counter_moves[i][j] = chess::NULL_MOVE; } } @@ -76,9 +76,9 @@ namespace search { counter_moves[last_move.get_from()][last_move.get_to()] = move; } - void update_butterfly_history(chess::Move move, int bonus) { - int scaled = bonus - butterfly[move.get_from()][move.get_to()] * std::abs(bonus) / 32768; - butterfly[move.get_from()][move.get_to()] += scaled; + static void update_history(Score &entry, int bonus) { + int scaled = bonus - entry * std::abs(bonus) / 32768; + entry += scaled; } }; } // namespace search \ No newline at end of file diff --git a/src/search/move_list.h b/src/search/move_list.h index 325472e..549dcd7 100644 --- a/src/search/move_list.h +++ b/src/search/move_list.h @@ -104,7 +104,7 @@ namespace search { } else if (move == history.counter_moves[last_move.get_from()][last_move.get_to()]) { return MOVE_SCORE_COUNTER; } else { - return history.butterfly[move.get_from()][move.get_to()]; + return history.main_history[board.get_stm()][move.get_from()][move.get_to()]; } } }; diff --git a/src/search/search_thread.h b/src/search/search_thread.h index 11d4a54..96ea625 100644 --- a/src/search/search_thread.h +++ b/src/search/search_thread.h @@ -406,7 +406,7 @@ namespace search { R -= pv_node; R += !improving; - R -= std::clamp(history.butterfly[move.get_from()][move.get_to()] / 4096, -2, 2); + R -= std::clamp(history.main_history[board.get_stm()][move.get_from()][move.get_to()] / 4096, -2, 2); Depth D = std::clamp(new_depth - R, 1, depth - 1); score = -search(D, -alpha - 1, -alpha, ss + 1); @@ -438,9 +438,9 @@ namespace search { if (score >= beta) { if (move.is_quiet()) { - history.add_cutoff(move, last_move, depth, ss->ply); + history.add_cutoff(board, move, last_move, depth, ss->ply); for (chess::Move *current_move = quiet_moves; current_move != next_quiet_move; current_move++) { - history.decrease_history(*current_move, depth); + history.decrease_history(board, *current_move, depth); } }