From add3a02ddd63c1438ddc011cbc1cf3fefbc4452a Mon Sep 17 00:00:00 2001 From: Martin Blicha Date: Fri, 30 Jul 2021 18:18:25 +0200 Subject: [PATCH] LibChess: Fix hashing of the chess board The hash function should take the board by reference, not by value. Also, the fact whether black can castle kingside or not was included twice in the hash, unnecesarily. --- Userland/Libraries/LibChess/Chess.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibChess/Chess.h b/Userland/Libraries/LibChess/Chess.h index 5a75a8c569..2a25972484 100644 --- a/Userland/Libraries/LibChess/Chess.h +++ b/Userland/Libraries/LibChess/Chess.h @@ -278,7 +278,7 @@ void Board::generate_moves(Callback callback, Color color) const template<> struct AK::Traits : public GenericTraits { - static unsigned hash(const Chess::Piece& piece) + static unsigned hash(Chess::Piece const& piece) { return pair_int_hash(static_cast(piece.color), static_cast(piece.type)); } @@ -286,7 +286,7 @@ struct AK::Traits : public GenericTraits { template<> struct AK::Traits : public GenericTraits { - static unsigned hash(const Chess::Board chess) + static unsigned hash(Chess::Board const& chess) { unsigned hash = 0; hash = pair_int_hash(hash, static_cast(chess.m_white_can_castle_queenside)); @@ -294,8 +294,6 @@ struct AK::Traits : public GenericTraits { hash = pair_int_hash(hash, static_cast(chess.m_black_can_castle_queenside)); hash = pair_int_hash(hash, static_cast(chess.m_black_can_castle_kingside)); - hash = pair_int_hash(hash, static_cast(chess.m_black_can_castle_kingside)); - Chess::Square::for_each([&](Chess::Square sq) { hash = pair_int_hash(hash, Traits::hash(chess.get_piece(sq))); return IterationDecision::Continue;