-
Notifications
You must be signed in to change notification settings - Fork 0
/
chessClasses.py
56 lines (47 loc) · 1.68 KB
/
chessClasses.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
#Player class containing data on pieces, color, state
class Player:
def __init__(self, pieces, moves, color):
self.pieces = pieces
self.targets = moves
self.color = color
self.possibleNextMoves = None
self.inCheck = False
#calculate next possible moves for player
def calcNextTargets(self):
targetList = []
for piece in self.pieces:
for move in piece.moveset:
targetList.append(move)
self.targets = targetList
def calcNextMoves(self):
moveList = []
for piece in self.pieces:
src = piece.board_pos
for move in piece.moveset:
dest = move
moveList.append((src,dest))
self.possibleNextMoves = moveList
#sets player status wrt check or not in check
def checkStatus(self, func, enemy):
self.inCheck = func(self, enemy)
#Piece class containing data on spot, color, type
class Piece:
def __init__(self, rank, color, pixel_pos, board_pos, moveset=None ):
self.color = color
self.rank = rank
self.strength = 0
self.protected = False
self.img = None
self.pixel_pos = pixel_pos
self.board_pos = board_pos
self.moveset = moveset
#draws piece sprite to screen
def draw(self, displaySurf):
displaySurf.blit(self.img, self.pixel_pos)
#calculates possible moves for piece
def setMoves(self, func, board, players):
self.moveset = func(self.rank,
self.color,
self.board_pos,
board,
players)