forked from marcusbuffett/command-line-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.py
More file actions
51 lines (42 loc) · 1.68 KB
/
Move.py
File metadata and controls
51 lines (42 loc) · 1.68 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
from Coordinate import Coordinate as C
import re
class Move :
def __init__(self, piece, newPos, pieceToCapture = None) :
self.notation = None
self.check = False
self.checkmate = False
self.kingsideCastle = False
self.queensideCastle = False
self.promotion = False
self.pessant = False
self.stalemate = False
self.piece = piece
self.oldPos = piece.position
self.newPos = newPos
self.pieceToCapture = pieceToCapture
#For en pessant and castling
self.specialMovePiece = None
#For castling
self.rookMove = None
def __str__(self) :
displayString = 'Old pos : ' + str(self.oldPos) + ' -- New pos : ' + str(self.newPos)
if self.notation :
displayString += ' Notation : ' + self.notation
if self.pessant :
displayString = 'Old pos : ' + str(self.oldPos) + ' -- New pos : ' + str(self.newPos) + ' -- Pawn taken : ' + str(self.specialMovePiece)
displayString += ' PESSANT'
return displayString
def __eq__(self, other) :
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):
return hash((self.oldPos, self.newPos))
def reverse(self) :
return Move(self.piece, self.piece.position, pieceToCapture = self.pieceToCapture)