Вам необходимо добавить правильное смещение к текущей позиции фигуры и вернуть список возможных юридических позиций.
может быть что-то вроде этого:
def get_possible_knight_moves(pos):
x, y = pos
possible_moves = []
for dx, dy in knight_offsets:
new_pos = (x + dx, y + dy)
if is_legal(new_pos):
possible_moves.append(new_pos)
return possible_moves
def is_legal(pos):
x, y = pos
return 0 <= x < 8 and 0 <= y < 8
knight_offsets = [(2, 1), (2, -1), (1, 2), (1, -2), (-2, 1), (-2, -1),(-1, 2),(-1, -2)]
pieceposition = (3 , 4)
movelist = get_possible_knight_moves(pieceposition)
print (movelist)
output:
[(5, 5), (5, 3), (4, 6), (4, 2), (1, 5), (1, 3), (2, 6), (2, 2)]
Для коня в положении (0, 0)
, вывод равен [(2, 1), (1, 2)]