Skip to content

Commit

Permalink
Separate history for sides
Browse files Browse the repository at this point in the history
Bench: 11079488
  • Loading branch information
SzilBalazs committed Aug 29, 2023
1 parent 021da63 commit cef57cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/search/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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;
}
}
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/search/move_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/search/search_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NON_PV_NODE>(D, -alpha - 1, -alpha, ss + 1);
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit cef57cd

Please sign in to comment.