Chess: Fix game not end if checkmate by promotion
This commit is contained in:
parent
d7fab3bd96
commit
7b391dd8f3
@ -1893,7 +1893,7 @@ local function update_formspec(meta)
|
|||||||
meta:set_string("formspec", formspec)
|
meta:set_string("formspec", formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_game_result(meta)
|
local function update_game_result(meta, lastMove)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local board_t = realchess.board_to_table(inv)
|
local board_t = realchess.board_to_table(inv)
|
||||||
|
|
||||||
@ -1913,9 +1913,6 @@ local function update_game_result(meta)
|
|||||||
whiteCanMove = true
|
whiteCanMove = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- assume lastMove was updated *after* the player moved
|
|
||||||
local lastMove = meta:get_string("lastMove")
|
|
||||||
|
|
||||||
local black_king_idx, white_king_idx = realchess.locate_kings(board_t)
|
local black_king_idx, white_king_idx = realchess.locate_kings(board_t)
|
||||||
if not black_king_idx or not white_king_idx then
|
if not black_king_idx or not white_king_idx then
|
||||||
minetest.log("error", "[xdecor] Chess: Insufficient kings on chessboard!")
|
minetest.log("error", "[xdecor] Chess: Insufficient kings on chessboard!")
|
||||||
@ -3111,16 +3108,19 @@ function realchess.move_piece(meta, pieceFrom, from_list, from_index, to_list, t
|
|||||||
add_to_eaten_list(meta, pieceTo)
|
add_to_eaten_list(meta, pieceTo)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local lastMove = meta:get_string("lastMove")
|
||||||
|
if lastMove == "" then lastMove = "black" end
|
||||||
|
|
||||||
local promo = meta:get_string("promotionActive") ~= ""
|
local promo = meta:get_string("promotionActive") ~= ""
|
||||||
if not promo then
|
if not promo then
|
||||||
update_game_result(meta)
|
update_game_result(meta, lastMove)
|
||||||
|
lastMove = meta:get_string("lastMove")
|
||||||
|
if lastMove == "" then lastMove = "black" end
|
||||||
end
|
end
|
||||||
update_formspec(meta)
|
update_formspec(meta)
|
||||||
|
|
||||||
local botColor = meta:get_string("botColor")
|
local botColor = meta:get_string("botColor")
|
||||||
if botColor == "" then botColor = "black" end
|
if botColor == "" then botColor = "black" end
|
||||||
local lastMove = meta:get_string("lastMove")
|
|
||||||
if lastMove == "" then lastMove = "black" end
|
|
||||||
local mode = meta:get_string("mode")
|
local mode = meta:get_string("mode")
|
||||||
local gameResult = meta:get_string("gameResult")
|
local gameResult = meta:get_string("gameResult")
|
||||||
-- Let the bot play when it its turn
|
-- Let the bot play when it its turn
|
||||||
@ -3208,6 +3208,7 @@ function realchess.promote_pawn(meta, color, promoteTo)
|
|||||||
meta:set_int("promotionPawnFromIdx", 0)
|
meta:set_int("promotionPawnFromIdx", 0)
|
||||||
meta:set_int("promotionPawnToIdx", 0)
|
meta:set_int("promotionPawnToIdx", 0)
|
||||||
realchess.update_state(meta, from_idx, to_idx, color, promoteFrom:get_name(), pstr)
|
realchess.update_state(meta, from_idx, to_idx, color, promoteFrom:get_name(), pstr)
|
||||||
|
update_game_result(meta, color)
|
||||||
update_formspec(meta)
|
update_formspec(meta)
|
||||||
|
|
||||||
local botColor = meta:get_string("botColor")
|
local botColor = meta:get_string("botColor")
|
||||||
|
Loading…
Reference in New Issue
Block a user