Chess: Add promotion to notation
This commit is contained in:
parent
4bfec061bb
commit
8808645384
@ -971,8 +971,13 @@ local fs = [[
|
|||||||
list[context;board;0.47,1.155;8,8;]
|
list[context;board;0.47,1.155;8,8;]
|
||||||
tableoptions[background=#00000000;highlight=#00000000;border=false]
|
tableoptions[background=#00000000;highlight=#00000000;border=false]
|
||||||
]]
|
]]
|
||||||
-- move; white piece; white halfmove; black piece; black halfmove
|
-- table columns for Chess notation.
|
||||||
.."tablecolumns[text;image," .. figurines_str .. ";text;image," .. figurines_str .. ";text]"
|
-- Columns: move no.; white piece; white halfmove; white promotion; black piece; black halfmove; black promotion
|
||||||
|
.."tablecolumns[" ..
|
||||||
|
"text;"..
|
||||||
|
"image," .. figurines_str .. ";text;image," .. figurines_str .. ";" ..
|
||||||
|
--"image,0=mailbox_blank16.png;" ..
|
||||||
|
"image," .. figurines_str .. ";text;image," .. figurines_str .. "]"
|
||||||
|
|
||||||
local function add_move_to_moves_list(meta, pieceFrom, pieceTo, from_idx, to_idx, special)
|
local function add_move_to_moves_list(meta, pieceFrom, pieceTo, from_idx, to_idx, special)
|
||||||
local moves_raw = meta:get_string("moves_raw")
|
local moves_raw = meta:get_string("moves_raw")
|
||||||
@ -995,7 +1000,7 @@ end
|
|||||||
local function get_moves_formstring(meta)
|
local function get_moves_formstring(meta)
|
||||||
local moves_raw = meta:get_string("moves_raw")
|
local moves_raw = meta:get_string("moves_raw")
|
||||||
if moves_raw == "" then
|
if moves_raw == "" then
|
||||||
return ","..MOVES_LIST_SYMBOL_EMPTY..",,"..MOVES_LIST_SYMBOL_EMPTY..",", 1
|
return "", 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local moves_split = string.split(moves_raw, ";")
|
local moves_split = string.split(moves_raw, ";")
|
||||||
@ -1014,7 +1019,7 @@ local function get_moves_formstring(meta)
|
|||||||
|
|
||||||
if special == "whiteWon" or special == "blackWon" or special == "draw" then
|
if special == "whiteWon" or special == "blackWon" or special == "draw" then
|
||||||
if not curPlayerIsWhite then
|
if not curPlayerIsWhite then
|
||||||
moves_out = moves_out .. ""..MOVES_LIST_SYMBOL_EMPTY..",,"
|
moves_out = moves_out .. ""..MOVES_LIST_SYMBOL_EMPTY..",," .. MOVES_LIST_SYMBOL_EMPTY .. ","
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if special == "whiteWon" then
|
if special == "whiteWon" then
|
||||||
@ -1065,12 +1070,12 @@ local function get_moves_formstring(meta)
|
|||||||
-- queenside castling
|
-- queenside castling
|
||||||
if from_x == 4 and to_x == 2 then
|
if from_x == 4 and to_x == 2 then
|
||||||
-- write "0–0–0"
|
-- write "0–0–0"
|
||||||
moves_out = moves_out .. MOVES_LIST_SYMBOL_EMPTY .. ",0–0–0"
|
moves_out = moves_out .. MOVES_LIST_SYMBOL_EMPTY .. ",0–0–0," .. MOVES_LIST_SYMBOL_EMPTY
|
||||||
castling = true
|
castling = true
|
||||||
-- kingside castling
|
-- kingside castling
|
||||||
elseif from_x == 4 and to_x == 6 then
|
elseif from_x == 4 and to_x == 6 then
|
||||||
-- write "0–0"
|
-- write "0–0"
|
||||||
moves_out = moves_out .. MOVES_LIST_SYMBOL_EMPTY .. ",0–0"
|
moves_out = moves_out .. MOVES_LIST_SYMBOL_EMPTY .. ",0–0," .. MOVES_LIST_SYMBOL_EMPTY
|
||||||
castling = true
|
castling = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1079,13 +1084,21 @@ local function get_moves_formstring(meta)
|
|||||||
moves_out = moves_out ..
|
moves_out = moves_out ..
|
||||||
pieceFrom_si_id .. "," .. -- piece image ID
|
pieceFrom_si_id .. "," .. -- piece image ID
|
||||||
coordFrom .. betweenCoordsSymbol .. coordTo .. -- coords in long algebraic notation, e.g. "e2e3"
|
coordFrom .. betweenCoordsSymbol .. coordTo .. -- coords in long algebraic notation, e.g. "e2e3"
|
||||||
enPassantSymbol -- written in case of an 'en passant' capture
|
enPassantSymbol .. "," -- written in case of an 'en passant' capture
|
||||||
|
|
||||||
|
-- Promotion?
|
||||||
|
if special:sub(1, 7) == "promo__" then
|
||||||
|
local promoSym = special:sub(8)
|
||||||
|
moves_out = moves_out .. get_figurine_id(promoSym)
|
||||||
|
else
|
||||||
|
moves_out = moves_out .. MOVES_LIST_SYMBOL_EMPTY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If White moved, fill up the rest of the row with empty space.
|
-- If White moved, fill up the rest of the row with empty space.
|
||||||
-- Required for validity of the table
|
-- Required for validity of the table
|
||||||
if curPlayerIsWhite and m == #moves_split then
|
if curPlayerIsWhite and m == #moves_split then
|
||||||
moves_out = moves_out .. "," .. MOVES_LIST_SYMBOL_EMPTY
|
moves_out = moves_out .. "," .. MOVES_LIST_SYMBOL_EMPTY .. ",," .. MOVES_LIST_SYMBOL_EMPTY
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2275,13 +2288,13 @@ function realchess.move_piece(meta, pieceFrom, from_list, from_index, to_list, t
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function realchess.update_state(meta, from_index, to_index, thisMove, promotionOverride)
|
function realchess.update_state(meta, from_index, to_index, thisMove, promoteFrom, promoteTo)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local board = board_to_table(inv)
|
local board = board_to_table(inv)
|
||||||
local pieceTo = board[to_index]
|
local pieceTo = board[to_index]
|
||||||
local pieceFrom = promotionOverride or board[from_index]
|
local pieceFrom = promoteFrom or board[from_index]
|
||||||
|
|
||||||
if not promotionOverride then
|
if not promoteFrom then
|
||||||
board[to_index] = board[from_index]
|
board[to_index] = board[from_index]
|
||||||
board[from_index] = ""
|
board[from_index] = ""
|
||||||
end
|
end
|
||||||
@ -2309,7 +2322,11 @@ function realchess.update_state(meta, from_index, to_index, thisMove, promotionO
|
|||||||
meta:set_string("lastMove", lastMove)
|
meta:set_string("lastMove", lastMove)
|
||||||
meta:set_int("lastMoveTime", minetest.get_gametime())
|
meta:set_int("lastMoveTime", minetest.get_gametime())
|
||||||
|
|
||||||
add_move_to_moves_list(meta, pieceFrom, pieceTo, from_index, to_index)
|
local special
|
||||||
|
if promoteTo then
|
||||||
|
special = "promo__"..promoteTo
|
||||||
|
end
|
||||||
|
add_move_to_moves_list(meta, pieceFrom, pieceTo, from_index, to_index, special)
|
||||||
add_to_eaten_list(meta, pieceTo)
|
add_to_eaten_list(meta, pieceTo)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2325,17 +2342,19 @@ function realchess.promote_pawn(meta, color, promoteTo)
|
|||||||
if promoteTo ~= "queen" then
|
if promoteTo ~= "queen" then
|
||||||
pstr = pstr .. "_1"
|
pstr = pstr .. "_1"
|
||||||
end
|
end
|
||||||
local stack
|
pstr = "realchess:" .. pstr
|
||||||
|
|
||||||
|
local promoteFrom
|
||||||
if color == "white" then
|
if color == "white" then
|
||||||
stack = inv:get_stack("board", to_idx)
|
promoteFrom = inv:get_stack("board", to_idx)
|
||||||
if stack:get_name():sub(11,14) == "pawn" then
|
if promoteFrom:get_name():sub(11,14) == "pawn" then
|
||||||
inv:set_stack("board", to_idx, "realchess:"..pstr)
|
inv:set_stack("board", to_idx, pstr)
|
||||||
promoted = true
|
promoted = true
|
||||||
end
|
end
|
||||||
elseif color == "black" then
|
elseif color == "black" then
|
||||||
stack = inv:get_stack("board", to_idx)
|
promoteFrom = inv:get_stack("board", to_idx)
|
||||||
if stack:get_name():sub(11,14) == "pawn" then
|
if promoteFrom:get_name():sub(11,14) == "pawn" then
|
||||||
inv:set_stack("board", to_idx, "realchess:"..pstr)
|
inv:set_stack("board", to_idx, pstr)
|
||||||
promoted = true
|
promoted = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2343,7 +2362,7 @@ function realchess.promote_pawn(meta, color, promoteTo)
|
|||||||
meta:set_string("promotionActive", "")
|
meta:set_string("promotionActive", "")
|
||||||
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, stack:get_name())
|
realchess.update_state(meta, from_idx, to_idx, color, promoteFrom:get_name(), pstr)
|
||||||
update_formspec(meta)
|
update_formspec(meta)
|
||||||
|
|
||||||
local aiColor = meta:get_string("aiColor")
|
local aiColor = meta:get_string("aiColor")
|
||||||
|
Loading…
Reference in New Issue
Block a user