Chess: Fix en passant may put own king at risk
This commit is contained in:
parent
e28f2a1844
commit
5e97bd81b7
@ -1500,6 +1500,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
||||
|
||||
local promotion = false
|
||||
local doublePawnStep = nil
|
||||
local en_passant_target = nil
|
||||
|
||||
-- PAWN
|
||||
if pieceFrom:sub(11,14) == "pawn" then
|
||||
@ -1563,7 +1564,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
||||
-- en passant
|
||||
if can_capture_en_passant(meta, "black", xy_to_index(to_x, from_y)) then
|
||||
can_capture = true
|
||||
inv:set_stack(to_list, xy_to_index(to_x, from_y), "")
|
||||
en_passant_target = xy_to_index(to_x, from_y)
|
||||
end
|
||||
end
|
||||
if not can_capture then
|
||||
@ -1633,7 +1634,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
||||
-- en passant
|
||||
if can_capture_en_passant(meta, "white", xy_to_index(to_x, from_y)) then
|
||||
can_capture = true
|
||||
inv:set_stack(to_list, xy_to_index(to_x, from_y), "")
|
||||
en_passant_target = xy_to_index(to_x, from_y)
|
||||
end
|
||||
end
|
||||
if not can_capture then
|
||||
@ -1920,6 +1921,8 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
||||
local blackAttacked = attacked("black", black_king_idx, board)
|
||||
local whiteAttacked = attacked("white", white_king_idx, board)
|
||||
|
||||
-- Refuse to move if it would put or leave the own king
|
||||
-- under attack
|
||||
if blackAttacked and thisMove == "black" then
|
||||
return
|
||||
end
|
||||
@ -1927,6 +1930,10 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
||||
return
|
||||
end
|
||||
|
||||
if en_passant_target then
|
||||
inv:set_stack(to_list, en_passant_target, "")
|
||||
end
|
||||
|
||||
if kingMoved and thisMove == "white" then
|
||||
meta:set_int("castlingWhiteL", 0)
|
||||
meta:set_int("castlingWhiteR", 0)
|
||||
|
Loading…
Reference in New Issue
Block a user