forked from SigmaProductions/sigmaChess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpieces.py
135 lines (109 loc) · 4.95 KB
/
pieces.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from enum import Enum
import pathing
class factionColor (Enum):
FACTION_WHITE = 1;
FACTION_BLACK = 2;
class chessPiece:
name = None
def __init__(self, hX, hY, faction):
self.x = hX;
self.y = hY;
self.faction=faction;
class piecePawn(chessPiece):
name = "pawn"
def checkAttack(self, boardArray, coordHorizontal, coordVert):
square = boardArray[coordHorizontal][coordVert];
if square is None:
return False;
if self.faction == factionColor.FACTION_WHITE:
if coordVert == self.y + 1 and (abs(coordHorizontal - self.x) == 1):
if square.faction is not self.faction:
return True;
return False;
elif self.faction == factionColor.FACTION_BLACK:
if coordVert + 1 == self.y and (abs(coordHorizontal - self.x) == 1):
if square.faction is not self.faction:
return True;
return False;
def checkMove(self, boardArray, coordHorizontal, coordVert):
square = boardArray[coordHorizontal][coordVert];
if square is not None:
return False;
if self.faction == factionColor.FACTION_WHITE:
if coordHorizontal == self.x and self.y == 1 and coordVert == self.y + 2:
return True;
elif coordHorizontal == self.x and coordVert == self.y + 1:
return True;
return False;
else:
if coordHorizontal == self.x and self.y == 6 and coordVert == self.y - 2:
return True;
if coordHorizontal == self.x and coordVert == self.y - 1:
return True;
return False;
class pieceKing(chessPiece):
name = "king"
def checkAttack(self, boardArray, coordHorizontal, coordVert):
square=boardArray[coordHorizontal][coordVert];
if (abs(coordHorizontal - self.x) <= 1) and (abs(coordVert - self.y) <= 1):
if square is not None and square.faction is not self.faction:
return True;
return False;
def checkMove(self, boardArray, coordHorizontal, coordVert):
square=boardArray[coordHorizontal][coordVert];
if square is not None:
return False;
if (abs(coordHorizontal - self.x) <= 1) and (abs(coordVert - self.y) <= 1):
return True;
return False;
class pieceRook(chessPiece):
name = "rook"
def checkAttack(self, boardArray, coordHorizontal, coordVert):
return self.checkMove(boardArray, coordHorizontal, coordVert)
def checkMove(self, boardArray, coordHorizontal, coordVert):
square = boardArray[coordHorizontal][coordVert]
emptyPath = pathing.piecePath(self.x, self.y, boardArray, coordHorizontal, coordVert)
if (coordVert == self.y or coordHorizontal == self.x) and emptyPath is not False:
if square is None:
return True
if square.faction is not self.faction:
return True
return False
class pieceBishop(chessPiece):
name = "bishop"
def checkAttack(self, boardArray, coordHorizontal, coordVert):
return self.checkMove(boardArray, coordHorizontal, coordVert)
def checkMove(self, boardArray, coordHorizontal, coordVert):
square = boardArray[coordHorizontal][coordVert]
emptyPath = pathing.piecePath(self.x, self.y,boardArray, coordHorizontal, coordVert)
if abs(coordHorizontal - self.x) == abs(coordVert - self.y) and emptyPath is not False:
if square is None:
return True
if square.faction is not self.faction:
return True
return False
class pieceKnight(chessPiece):
name = "knight"
def checkAttack(self, boardArray, coordHorizontal, coordVert):
return self.checkMove(boardArray, coordHorizontal, coordVert)
def checkMove(self, boardArray, coordHorizontal, coordVert):
square = boardArray[coordHorizontal][coordVert]
if abs(coordHorizontal - self.x) == 2 and abs(coordVert - self.y) == 1 or abs(coordVert - self.y) == 2 and abs(coordHorizontal - self.x) == 1:
if square is None:
return True
if square.faction is not self.faction:
return True
return False
class pieceQueen(chessPiece):
name = "queen"
def checkAttack(self, boardArray, coordHorizontal, coordVert):
return self.checkMove(boardArray, coordHorizontal, coordVert)
def checkMove(self, boardArray, coordHorizontal, coordVert):
square = boardArray[coordHorizontal][coordVert]
emptyPath = pathing.piecePath(self.x, self.y,boardArray, coordHorizontal, coordVert)
if (abs(coordHorizontal - self.x) == abs(coordVert - self.y) or (coordVert == self.y or coordHorizontal == self.x)) and emptyPath is not False:
if square is None:
return True
if square.faction is not self.faction:
return True
return False