2023-06-08 16:02:55 +02:00
|
|
|
from piece import Piece
|
2023-06-13 00:08:24 +02:00
|
|
|
from board import Board
|
|
|
|
from square import Square
|
2023-06-08 16:02:55 +02:00
|
|
|
class Rook(Piece):
|
2023-06-19 20:14:10 +02:00
|
|
|
def rook_moves(self, piece, row, column):
|
2023-06-19 20:11:22 +02:00
|
|
|
|
|
|
|
self.direction = [
|
|
|
|
(0, 1),
|
|
|
|
(0, -1),
|
|
|
|
(1, 0),
|
|
|
|
(-1, 0)
|
|
|
|
]
|
2023-06-13 00:08:24 +02:00
|
|
|
for dir in self.direction:
|
|
|
|
self.left, self.right = dir
|
|
|
|
self.possible_row = row + self.left
|
|
|
|
self.possible_column = column + self.right
|
|
|
|
while True:
|
|
|
|
if Square.on_board(self.possible_row, self.possible_column) is True:
|
|
|
|
if self.board.boardlist[self.possible_row][self.possible_column].has_piece() is False:
|
|
|
|
piece.add_moves((self.possible_row, self.possible_column))
|
|
|
|
self.possible_row = self.possible_row + self.left
|
|
|
|
self.possible_column = self.possible_column + self.right
|
|
|
|
elif self.board.boardlist[self.possible_row][self.possible_column].is_rival(piece.color) is True:
|
|
|
|
piece.add_moves((self.possible_row, self.possible_column))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
break
|