extracted some logic to the piece class and

implemented the knights legal moves
This commit is contained in:
Karma Riuk
2025-01-30 17:07:19 +01:00
parent 6b0a134230
commit 96b9b3db86
4 changed files with 27 additions and 17 deletions

View File

@ -1,5 +1,16 @@
from .piece import Piece
class Knight(Piece):
pass
def legal_moves(self, board: "Board") -> list["Move"]:
ret = []
for dx, dy in [
(+2, +1), (+1, +2), # north east
(+2, -1), (+1, -2), # south east
(-2, -1), (-1, -2), # south west
(-2, +1), (-1, +2), # north west
]:
move = self._move_for_position(board, self.pos.x + dx, self.pos.y + dy)
if move is not None:
ret.append(move)
return ret