-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.py
235 lines (169 loc) · 7.42 KB
/
objects.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import pygame
from pygame.locals import *
import math
class Sprite():
def __init__(self):
self.pawn_w = pygame.image.load("images\\pawn_w.png")
self.pawn_b = pygame.image.load("images\\pawn_b.png")
self.knight_w = pygame.image.load("images\\knight_w.png")
self.knight_b = pygame.image.load("images\\knight_b.png")
self.bishop_w = pygame.image.load("images\\bishop_w.png")
self.bishop_b = pygame.image.load("images\\bishop_b.png")
self.thief_w = pygame.image.load("images\\thief_w.png")
self.thief_b = pygame.image.load("images\\thief_b.png")
self.king_w = pygame.image.load("images\\king_w.png")
self.king_b = pygame.image.load("images\\king_b.png")
self.queen_w = pygame.image.load("images\\queen_w.png")
self.queen_b = pygame.image.load("images\\queen_b.png")
self.rook_w = pygame.image.load("images\\rook_w.png")
self.rook_b = pygame.image.load("images\\rook_b.png")
class Player():
def __init__(self, color, pieces):
self.color = color
self.pieces = pieces
self.capturedPieces = []
self.is_turn = False
def toggle_turn(self):
self.is_turn = not self.is_turn
class Piece():
def __init__(self, image, color): #color: 0 = white, 1 = black
self.image = image
#TODO, remove self posistion, rely on tile coordinates
self.color = color
def move(self, tile):
self.tile = tile
class Pawn_White(Piece):
def can_move(self, tile):
if tile.X == self.tile.X:
if tile.Y == self.tile.Y - 1 and tile.Z == self.tile.Z:
return True
if tile.Y == self.tile.Y and tile.Z == self.tile.Z+1:
return True
else:
return False
class Rook_White(Piece):
def can_move(self, tile):
if tile.X == self.tile.X and tile.Y == self.tile.Y and tile.Z != self.tile.Z:
return True
elif tile.X == self.tile.X and tile.Y != self.tile.Y and tile.Z == self.tile.Z:
return True
elif tile.X != self.tile.X and tile.Y == self.tile.Y and tile.Z == self.tile.Z:
return True
else:
return False
class Bishop_White(Piece):
def can_move(self, tile):
if tile.X != self.tile.X or tile.Y != self.tile.Y or tile.Z != self.tile.Z:
if tile.Z == self.tile.Z:
if math.fabs(tile.Y-self.tile.Y) == math.fabs(tile.X-self.tile.X):
return True
elif tile.X == self.tile.X:
if math.fabs(tile.Y-self.tile.Y) == math.fabs(tile.Z-self.tile.Z):
return True
elif tile.Y == self.tile.Y:
if math.fabs(tile.X-self.tile.X) == math.fabs(tile.Z-self.tile.Z):
return True
else:
return False
else:
return False
class Thief_White(Piece):
def can_move(self, tile):
if tile.X != self.tile.X or tile.Y != self.tile.Y or tile.Z != self.tile.Z:
if math.fabs(tile.Y-self.tile.Y) == math.fabs(tile.X-self.tile.X) and math.fabs(tile.X-self.tile.X) == math.fabs(tile.Z - self.tile.Z):
return True
else:
return False
class Queen_White(Piece):
def can_move(self, tile):
if tile.X != self.tile.X or tile.Y != self.tile.Y or tile.Z != self.tile.Z:
if tile.Z == self.tile.Z:
if math.fabs(tile.Y-self.tile.Y) == math.fabs(tile.X-self.tile.X):
return True
elif tile.X == self.tile.X or tile.Y == self.tile.Y:
return True
elif tile.X == self.tile.X:
if math.fabs(tile.Y-self.tile.Y) == math.fabs(tile.Z-self.tile.Z):
return True
elif tile.Y == self.tile.Y or tile.Y == self.tile.Y:
return True
elif tile.Y == self.tile.Y:
if math.fabs(tile.X-self.tile.X) == math.fabs(tile.Z-self.tile.Z):
return True
if tile.X == self.tile.X or tile.Z == self.tile.Z:
return True
elif math.fabs(tile.Y-self.tile.Y) == math.fabs(tile.X-self.tile.X) and math.fabs(tile.X-self.tile.X) == math.fabs(tile.Z - self.tile.Z):
return True
else:
return False
else: return False
class King_White(Piece):
def can_move(self, tile):
if math.fabs(tile.X - self.tile.X) <= 1 and math.fabs(tile.Y - self.tile.Y) <= 1 and math.fabs(tile.Z - self.tile.Z) <= 1:
return True
else:
return False
class Knight_White(Piece):
def can_move(self, tile):
if tile.Z == self.tile.Z:
if math.fabs(tile.X-self.tile.X) == 2 and math.fabs(tile.Y-self.tile.Y) == 1:
return True
elif math.fabs(tile.X-self.tile.X) == 1 and math.fabs(tile.Y-self.tile.Y) == 2:
return True
else:
return False
elif tile.X == self.tile.X:
if math.fabs(tile.Z-self.tile.Z) == 2 and math.fabs(tile.Y-self.tile.Y) == 1:
return True
elif math.fabs(tile.Z-self.tile.Z) == 1 and math.fabs(tile.Y-self.tile.Y) == 2:
return True
else:
return False
elif tile.Y == self.tile.Y:
if math.fabs(tile.Z-self.tile.Z) == 2 and math.fabs(tile.X-self.tile.X) == 1:
return True
elif math.fabs(tile.Z-self.tile.Z) == 1 and math.fabs(tile.X-self.tile.X) == 2:
return True
else:
return False
else:
return False
class Pawn_Black(Piece):
def can_move(self, tile):
if tile.X == self.tile.X:
if tile.Y == self.tile.Y + 1 and tile.Z == self.tile.Z:
return True
if tile.Y == self.tile.Y and tile.Z == self.tile.Z-1:
return True
else:
return False
class Rook_Black(Rook_White):
pass
class Bishop_Black(Bishop_White):
pass
class Thief_Black(Thief_White):
pass
class Queen_Black(Queen_White):
pass
class King_Black(King_White):
pass
class Knight_Black(Knight_White):
pass
class Tile():
def __init__(self, rank, file, board):
self.X = rank
self.Y = file
self.Z = board
self.X_coordinate = (240*(4-board) + 60) + 40*file
self.Y_coordinate = (100*(4-board) + 80) + 40*rank
self.pos = (self.X_coordinate, self.Y_coordinate)
class Board(list):
def __init__(self, number, image):
for n in range(5):
self.append([Tile(i, n, number) for i in range(5)])
self.image = image
self.pos = (240*number + 60, 100*number + 80 )
class FullBoard(list):
def __init__(self, images):
for board in range(5):
self.append(Board(board, images[board]))