-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare.py
40 lines (29 loc) · 1.07 KB
/
square.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
class Square:
ALPHACOLS = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h'}
def __init__(self, row, col, piece=None):
self.row = row
self.col = col
self.piece = piece
self.alphacol = self.ALPHACOLS[col]
def __eq__(self, other):
return self.row == other.row and self.col == other.col
def has_piece(self):
return self.piece != None
def isempty(self):
return not self.has_piece()
def has_team_piece(self, color):
return self.has_piece() and self.piece.color == color
def has_enemy_piece(self, color):
return self.has_piece() and self.piece.color != color
def isempty_or_enemy(self, color):
return self.isempty() or self.has_enemy_piece(color)
@staticmethod
def in_range(*args):
for arg in args:
if arg < 0 or arg > 7:
return False
return True
@staticmethod
def get_alphacol(col):
ALPHACOLS = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h'}
return ALPHACOLS[col]