Szachy/knight.py

22 lines
919 B
Python
Raw Normal View History

2023-06-08 16:02:55 +02:00
from piece import Piece
2023-06-13 00:08:24 +02:00
from board import Board
2023-06-08 16:02:55 +02:00
from square import Square
class Knight(Piece):
2023-06-13 00:08:24 +02:00
def knight_moves(self, piece, row, column):
self.possible_moves = [
(row + 2, column - 1),
(row + 2, column + 1),
(row + 1, column + 2),
(row - 1, column + 2),
(row - 2, column + 1),
(row - 2, column - 1),
(row - 1, column - 2),
(row + 1, column - 2)
]
for self.possible_move in self.possible_moves:
self.possible_row, self.possible_column = self.possible_move
if Square.on_board(self.possible_row, self.possible_column):
if self.board.boardlist[self.possible_row][self.possible_column].empty_or_rival(piece.color):
self.final = (self.possible_row, self.possible_column)
piece.add_moves(self.final)