-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueen.py
24 lines (22 loc) · 853 Bytes
/
Queen.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
from Piece import Piece
#Queen
class Queen(Piece):
def valid_moves(self, board):
moves = []
directions = [(-1, -1), (1, 1), (1, -1), (-1, 1), (-1, 0), (1, 0), (0, -1), (0, 1)]
row, col = self.position
for direction in directions:
for i in range(1, 8):
new_row = row + direction[0] * i
new_col = col + direction[1] * i
if 0 <= new_row < 8 and 0 <= new_col < 8:
if board[new_row][new_col] is None:
moves.append((new_row, new_col))
elif board[new_row][new_col].color != self.color:
moves.append((new_row, new_col))
break
else:
break
else:
break
return moves