-
Notifications
You must be signed in to change notification settings - Fork 0
/
King.py
78 lines (61 loc) · 2.18 KB
/
King.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
from Piece import Piece
class King(Piece):
def __init__(self, column, row, colour):
self.position = column + row
self.colour = colour
self.shape = colour[0] + "K"
def validMove(self, start, finish, player, destination, board):
si = self.columns.index(start[0])
fi = self.columns.index(finish[0])
sr = self.rows.index(start[1]) + 1
fr = self.rows.index(finish[1]) + 1
if player.colour != destination.colour:
if fr == sr + 1:
if fi == si:
return True
elif fi == si + 1:
return True
elif fi == si - 1:
return True
elif fr == sr - 1:
if fi == si:
return True
elif fi == si + 1:
return True
elif fi == si - 1:
return True
elif fr == sr:
if fi == si + 1:
return True
elif fi == si - 1:
return True
return False
def getMoves(self, board):
col = self.columns.index(position[0])
row = self.rows.index(position[1])
moves = []
cell = self.columns[col+1] + self.rows[row+1]
if cell in board.keys():
moves.append(cell)
cell = self.columns[col+1] + self.rows[row]
if cell in board.keys():
moves.append(cell)
cell = self.columns[col+1] + self.rows[row-1]
if cell in board.keys():
moves.append(cell)
cell = self.columns[col] + self.rows[row+1]
if cell in board.keys():
moves.append(cell)
cell = self.columns[col] + self.rows[row-1]
if cell in board.keys():
moves.append(cell)
cell = self.columns[col-1] + self.rows[row+1]
if cell in board.keys():
moves.append(cell)
cell = self.columns[col-1] + self.rows[row-1]
if cell in board.keys():
moves.append(cell)
cell = self.columns[col-1] + self.rows[row]
if cell in board.keys():
moves.append(cell)
return moves