1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:47:35 +00:00

LibChess: Only save hash of board state for repetition checking

This more than doubles the number of nodes that MCTS can search for a
given time limit, and greatly reduces memory usage.
This commit is contained in:
Peter Elliott 2021-06-19 14:49:53 -06:00 committed by Andreas Kling
parent 675b8ba995
commit 57bb4d1aec
2 changed files with 9 additions and 10 deletions

View file

@ -579,14 +579,12 @@ bool Board::apply_move(const Move& move, Color color)
bool Board::apply_illegal_move(const Move& move, Color color)
{
Board clone = *this;
clone.m_previous_states = {};
clone.m_moves = {};
auto state = Traits<Board>::hash(*this);
auto state_count = 0;
if (m_previous_states.contains(clone))
state_count = m_previous_states.get(clone).value();
if (m_previous_states.contains(state))
state_count = m_previous_states.get(state).value();
m_previous_states.set(clone, state_count + 1);
m_previous_states.set(state, state_count + 1);
m_moves.append(move);
m_turn = opposing_color(color);
@ -758,7 +756,7 @@ Board::Result Board::game_result() const
if (m_moves_since_capture == 50 * 2)
return Result::FiftyMoveRule;
auto repeats = m_previous_states.get(*this);
auto repeats = m_previous_states.get(Traits<Board>::hash(*this));
if (repeats.has_value()) {
if (repeats.value() == 3)
return Result::ThreeFoldRepetition;