Chess: Add castling to possible moves detection

This commit is contained in:
Wuzzy 2023-07-14 16:12:52 +02:00
parent 74f8dc3bf9
commit 04dabe4091

View File

@ -589,6 +589,9 @@ local function get_theoretical_moves_from(meta, board, from_idx)
-- KING
elseif piece == "king" then
if attacked(color, xy_to_index(to_x, to_y), board) then
moves[to_idx] = nil
else
local dx = from_x - to_x
local dy = from_y - to_y
@ -601,11 +604,11 @@ local function get_theoretical_moves_from(meta, board, from_idx)
end
if dx > 1 or dy > 1 then
local cc = can_castle(meta, board, "board", from_idx, to_idx)
if not cc then
moves[to_idx] = nil
end
if attacked(color, xy_to_index(to_x, to_y), board) then
moves[to_idx] = nil
end
end
end
end