From a72faadd25af5bf7d80aab9d9adf48e765bed630 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Thu, 14 Jun 2012 19:52:12 +0200 Subject: [PATCH] Refactor killer moves --- src/game.cpp | 2 +- src/game.h | 13 +++++++++---- src/search.cpp | 15 +++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 4f1f130..703a236 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -109,7 +109,7 @@ void Game::del_position() /* * Killer move setter for the Killer Heuristic in move ordering. */ -void Game::set_killer_move(int depth, Move move) +void Game::set_killer(const Move move, const int depth) { if (move != killer_moves[depth][0]) { killer_moves[depth][1] = killer_moves[depth][0]; diff --git a/src/game.h b/src/game.h index ab5b667..3a18ecd 100644 --- a/src/game.h +++ b/src/game.h @@ -84,11 +84,16 @@ class Game // Killer Moves void clear_killers(); - Move killer_move(int depth, int index) { + /* + Move killer(int depth, int index) { return killer_moves[depth][index]; - } - void set_killer_move(int depth, Move move); - bool is_killer_move(int depth, Move move) { + }; + */ + Move (&killers(const int depth))[MAX_KILLERS] { + return killer_moves[depth]; + }; + void set_killer(const Move move, const int depth); + bool is_killer(const Move move, const int depth) { return (move == killer_moves[depth][0] || move == killer_moves[depth][1]); }; diff --git a/src/search.cpp b/src/search.cpp index 9ebf51f..5606a87 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -203,10 +203,9 @@ int Game::search(int alpha, int beta, int depth, const int ply) // Killer moves need pseudo legality checking before we can use them, // but they can cause a cut-off and dispense to generate quiet moves // so it's worth it. - for (int i = 0; i < MAX_KILLERS; ++i) { - Move killer = killer_move(depth, i); - if (is_legal(killer)) { - moves.add(killer, KILLERS); + for (const Move &killer_move : killers(depth)) { + if (is_legal(killer_move)) { + moves.add(killer_move, KILLERS); } } @@ -233,7 +232,7 @@ int Game::search(int alpha, int beta, int depth, const int ply) if (best_score >= beta) { // Beta cut-off // Update killer moves if (!move.is_capture()) { - set_killer_move(depth, move); + set_killer(move, depth); } best_move = move; @@ -250,7 +249,7 @@ int Game::search(int alpha, int beta, int depth, const int ply) const bool fp_allowed = !is_in_check && !is_giving_check && - !is_killer_move(depth, move) && + !is_killer(move, depth) && !is_dangerous(move) && !move.is_castle() && legal_move_found && @@ -274,7 +273,7 @@ int Game::search(int alpha, int beta, int depth, const int ply) const bool lmr_allowed = !is_in_check && !is_giving_check && - !is_killer_move(depth, move) && + !is_killer(move, depth) && !move.is_capture() && !move.is_promotion(); @@ -301,7 +300,7 @@ int Game::search(int alpha, int beta, int depth, const int ply) best_move = move; if (score >= beta) { // Sufficient to cause a cut-off? if (!move.is_capture()) { - set_killer_move(depth, move); // Update killer moves + set_killer(move, depth); // Update killer moves } goto transposition; -- 2.11.4.GIT