-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.py
More file actions
63 lines (55 loc) · 2.09 KB
/
Move.py
File metadata and controls
63 lines (55 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
from Coordinate import Coordinate as C
from Piece import Piece
class Move:
def __init__(self,piece: Piece,newPos: C,pieceToCapture: Optional[Piece] = None) -> None:
self.notation = ''
self.checkmate = False
self.kingsideCastle = False
self.queensideCastle = False
self.promotion = False
self.passant = False
self.stalemate = False
self.piece = piece
self.oldPos = piece.position
self.newPos = newPos
self.pieceToCapture = pieceToCapture
# For en passant and castling
# TODO: specialMovePiece should be a 'Piece' type to satisfy mypy
self.specialMovePiece = None
# For castling
# TODO: rookMove should be a 'Move' type to satisfy mypy
self.rookMove = None
def __str__(self) -> str:
displayString = 'Old pos : ' + str(self.oldPos) + \
' -- New pos : ' + str(self.newPos)
if self.notation:
displayString += ' Notation : ' + self.notation
if self.passant:
displayString = 'Old pos : ' + str(self.oldPos) + \
' -- New pos : ' + str(self.newPos) + \
' -- Pawn taken : ' + str(self.specialMovePiece)
displayString += ' PASSANT'
return displayString
def __eq__(self, other: object) -> bool:
if not isinstance(other, Move):
return NotImplemented
if (
self.oldPos == other.oldPos and self.newPos == other.newPos
and self.specialMovePiece == other.specialMovePiece
):
if not self.specialMovePiece:
return True
if (
self.specialMovePiece
and self.specialMovePiece == other.specialMovePiece
):
return True
else:
return False
else:
return False
def __hash__(self) -> int:
return hash((self.oldPos, self.newPos))