Chess: Fix broken loss of castling rights
This commit is contained in:
parent
36e2aab3b6
commit
2ef3d97c7a
@ -1433,7 +1433,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
|||||||
local lastMove = meta:get_string("lastMove")
|
local lastMove = meta:get_string("lastMove")
|
||||||
local playerWhite = meta:get_string("playerWhite")
|
local playerWhite = meta:get_string("playerWhite")
|
||||||
local playerBlack = meta:get_string("playerBlack")
|
local playerBlack = meta:get_string("playerBlack")
|
||||||
local castled = false
|
local kingMoved = false
|
||||||
local thisMove -- Will replace lastMove when move is legal
|
local thisMove -- Will replace lastMove when move is legal
|
||||||
|
|
||||||
if pieceFrom:find("white") then
|
if pieceFrom:find("white") then
|
||||||
@ -1701,12 +1701,23 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if thisMove == "white" or thisMove == "black" then
|
-- Lose castling right when moving rook
|
||||||
if pieceFrom:sub(-1) == "1" then
|
if thisMove == "white" then
|
||||||
|
if from_index == 57 then
|
||||||
|
-- queenside white rook
|
||||||
meta:set_int("castlingWhiteL", 0)
|
meta:set_int("castlingWhiteL", 0)
|
||||||
elseif pieceFrom:sub(-1) == "2" then
|
elseif from_index == 64 then
|
||||||
|
-- kingside white rook
|
||||||
meta:set_int("castlingWhiteR", 0)
|
meta:set_int("castlingWhiteR", 0)
|
||||||
end
|
end
|
||||||
|
elseif thisMove == "black" then
|
||||||
|
if from_index == 1 then
|
||||||
|
-- queenside black rook
|
||||||
|
meta:set_int("castlingBlackL", 0)
|
||||||
|
elseif from_index == 8 then
|
||||||
|
-- kingside black rook
|
||||||
|
meta:set_int("castlingBlackR", 0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- KNIGHT
|
-- KNIGHT
|
||||||
@ -1888,7 +1899,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
|||||||
inv:set_stack(from_list, rook_goal, rook_name)
|
inv:set_stack(from_list, rook_goal, rook_name)
|
||||||
inv:set_stack(from_list, rook_start, "")
|
inv:set_stack(from_list, rook_start, "")
|
||||||
check = false
|
check = false
|
||||||
castled = true
|
kingMoved = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if check then
|
if check then
|
||||||
@ -1904,6 +1915,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
kingMoved = true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1925,10 +1937,10 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if castled and thisMove == "white" then
|
if kingMoved and thisMove == "white" then
|
||||||
meta:set_int("castlingWhiteL", 0)
|
meta:set_int("castlingWhiteL", 0)
|
||||||
meta:set_int("castlingWhiteR", 0)
|
meta:set_int("castlingWhiteR", 0)
|
||||||
elseif castled and thisMove == "black" then
|
elseif kingMoved and thisMove == "black" then
|
||||||
meta:set_int("castlingBlackL", 0)
|
meta:set_int("castlingBlackL", 0)
|
||||||
meta:set_int("castlingBlackR", 0)
|
meta:set_int("castlingBlackR", 0)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user