-
Notifications
You must be signed in to change notification settings - Fork 2
/
rook.py
43 lines (40 loc) · 1.35 KB
/
rook.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
from piece import Piece
class Rook(Piece):
def __init__(self, row, column, piece_info):
super().__init__(row, column, piece_info)
self.moved = False # required for castling
def findAllMoves(self, board):
moves = []
i, j = self.row - 1, self.column
while i >= 0:
if board[i][j].piece != None:
if self.color != board[i][j].piece.color:
moves.append((i, j))
break
moves.append((i, j))
i -= 1
i, j = self.row + 1, self.column
while i < 8:
if board[i][j].piece != None:
if self.color != board[i][j].piece.color:
moves.append((i, j))
break
moves.append((i, j))
i += 1
i, j = self.row, self.column - 1
while j >= 0:
if board[i][j].piece != None:
if self.color != board[i][j].piece.color:
moves.append((i, j))
break
moves.append((i, j))
j -= 1
i, j = self.row, self.column + 1
while j < 8:
if board[i][j].piece != None:
if self.color != board[i][j].piece.color:
moves.append((i, j))
break
moves.append((i, j))
j += 1
return moves