Skip to content

Commit

Permalink
added hash
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalk11 committed Oct 27, 2024
1 parent d4b3190 commit 3c14407
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,8 @@ def restore(self, board: Board) -> None:
board.halfmove_clock = self.halfmove_clock
board.fullmove_number = self.fullmove_number

#from numba.experimental import jitclass
#@jitclass
class Board(BaseBoard):
"""
A :class:`~chess.BaseBoard`, additional information representing
Expand Down Expand Up @@ -3817,14 +3819,21 @@ def _repr_svg_(self) -> str:

def __eq__(self, board: object) -> bool:
if isinstance(board, Board):
return (
self.halfmove_clock == board.halfmove_clock and
self.fullmove_number == board.fullmove_number and
type(self).uci_variant == type(board).uci_variant and
self._transposition_key() == board._transposition_key())
return hash(self) == hash(board)

else:
return NotImplemented

def __hash__(self) -> int:
return hash((
self.pawns, self.knights, self.bishops, self.rooks,
self.queens, self.kings,
self.occupied_co[WHITE], self.occupied_co[BLACK],
self.turn, self.castling_rights, self.ep_square,
self.halfmove_clock, self.fullmove_number,
type(self).uci_variant, self.chess960
))

def apply_transform(self, f: Callable[[Bitboard], Bitboard]) -> None:
super().apply_transform(f)
self.clear_stack()
Expand Down

0 comments on commit 3c14407

Please sign in to comment.