Skip to content

Commit 4fd714f

Browse files
committed
为Move类增加__hash__方法
1 parent acb4494 commit 4fd714f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

cchess/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def from_unicode(cls, unicode: str):
568568
return cls.from_symbol(UNICODE_TO_PIECE_SYMBOLS[unicode])
569569

570570

571-
@dataclasses.dataclass(unsafe_hash=True)
571+
@dataclasses.dataclass
572572
class Move:
573573
def __init__(self, from_square: Square, to_square: Square):
574574
assert from_square in SQUARES, f"from_square out of range: {from_square!r}"
@@ -614,6 +614,9 @@ def __bool__(self):
614614
def null(cls):
615615
return cls(0, 0)
616616

617+
def __hash__(self):
618+
return hash((self.from_square, self.to_square))
619+
617620

618621
class BaseBoard:
619622
def __init__(self, board_fen: Optional[str] = STARTING_BOARD_FEN):

0 commit comments

Comments
 (0)