-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathking.py
More file actions
42 lines (32 loc) · 1 KB
/
Copy pathking.py
File metadata and controls
42 lines (32 loc) · 1 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
from piece import ChessPiece
class King(ChessPiece):
def __init__(self, color, row, col):
super().__init__(color, row, col)
def is_valid_move(self, row, col):
position = self.position
valid_moves = [
(-1, -1),
(-1, 0),
(-1, +1),
(0, -1),
(0, +1),
(+1, -1),
(+1, 0),
(+1, +1),
]
if (row - position[0], col - position[1]) not in valid_moves:
print("Invalid move: ", self.position, (row, col))
return False
return True
def move(self, row, col, board):
where_to = board[row][col]
if not self.is_valid_move(row, col) :
return False
if isinstance(where_to, ChessPiece):
if where_to.color == self.color:
return False
where_to.capture()
self.position = (row, col)
return True
def draw(self):
return "w$" if self.color == "white" else "b$"