mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:17:44 +00:00
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.
This commit is contained in:
parent
8e3431d56d
commit
add3a02ddd
1 changed files with 2 additions and 4 deletions
|
@ -278,7 +278,7 @@ void Board::generate_moves(Callback callback, Color color) const
|
|||
|
||||
template<>
|
||||
struct AK::Traits<Chess::Piece> : public GenericTraits<Chess::Piece> {
|
||||
static unsigned hash(const Chess::Piece& piece)
|
||||
static unsigned hash(Chess::Piece const& piece)
|
||||
{
|
||||
return pair_int_hash(static_cast<u32>(piece.color), static_cast<u32>(piece.type));
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ struct AK::Traits<Chess::Piece> : public GenericTraits<Chess::Piece> {
|
|||
|
||||
template<>
|
||||
struct AK::Traits<Chess::Board> : public GenericTraits<Chess::Board> {
|
||||
static unsigned hash(const Chess::Board chess)
|
||||
static unsigned hash(Chess::Board const& chess)
|
||||
{
|
||||
unsigned hash = 0;
|
||||
hash = pair_int_hash(hash, static_cast<u32>(chess.m_white_can_castle_queenside));
|
||||
|
@ -294,8 +294,6 @@ struct AK::Traits<Chess::Board> : public GenericTraits<Chess::Board> {
|
|||
hash = pair_int_hash(hash, static_cast<u32>(chess.m_black_can_castle_queenside));
|
||||
hash = pair_int_hash(hash, static_cast<u32>(chess.m_black_can_castle_kingside));
|
||||
|
||||
hash = pair_int_hash(hash, static_cast<u32>(chess.m_black_can_castle_kingside));
|
||||
|
||||
Chess::Square::for_each([&](Chess::Square sq) {
|
||||
hash = pair_int_hash(hash, Traits<Chess::Piece>::hash(chess.get_piece(sq)));
|
||||
return IterationDecision::Continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue