mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +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
Notes:
sideshowbarker
2024-07-19 17:21:58 +09:00
Author: https://github.com/blishko Commit: https://github.com/SerenityOS/serenity/commit/add3a02ddd6 Pull-request: https://github.com/SerenityOS/serenity/pull/9112 Reviewed-by: https://github.com/petelliott ✅
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…
Reference in a new issue