local p =
function chessboard(args, size, rows, cols, rev, trans, lightdark, altprefix, letters, numbers, header, footer, align, clear) function colchar(col) return (col <= 26) and ("abcdefghijklmnopqrstuvwxyz"):sub(col, col) or ("abcdefghijklmnopqrstuvwxyz"):sub(math.floor((col-1)/26), math.floor((col-1)/26)) .. ("abcdefghijklmnopqrstuvwxyz"):sub(col-math.floor((col-1)/26)*26, col-math.floor((col-1)/26)*26) end function image_square(pc, row, col, size, t, flip, altprefix) local colornames = local piecenames = local symnames = local color = mw.ustring.gsub(pc, '^.*(%w)(%w).*$', '%2') or local piece = mw.ustring.gsub(pc, '^.*(%w)(%w).*$', '%1') or local alt = altprefix .. colchar(col) .. row .. ' ' if (colornames[color] and piecenames[piece]) then alt = alt .. colornames[color] .. ' ' .. piecenames[piece] else alt = alt .. (symnames[piece .. color] or piece .. ' ' .. color) end local ld = t and 't' or ((((row + col + flip) % 2)
function letters_row(rev, num_lt, num_rt, cols) local res = '
local b = local caption =
if (letters_tp) then b = b .. letters_row(rev, numbers_lt, numbers_rt, cols) .. '\n' end for trow = 1,rows do local row = rev and trow or (rows - trow + 1) b = b .. '
0) and '#ffce9e' or '#d18b47' b = b .. '
if footer:match('^%s*$') then else caption = '
' .. footer .. '
\n' end b = '
if noframe then return b else return '
' .. '
' .. header .. '
' .. '\n
\n' .. b .. '\n' .. caption .. '
' end end
function convertFenToArgs(fen) -- converts FEN notation to an array of positions, offset by 2 local res = -- Loop over rows, which are delimited by / for srow in string.gmatch("/" .. fen, "/%w+") do -- Loop over all letters and numbers in the row for piece in srow:gmatch("%w") do if (piece:match("%d")) then -- if a digit for k=1,piece do table.insert(res,' ') end else -- not a digit local color = piece:match('%u') and 'l' or 'd' piece = piece:lower table.insert(res, piece .. color) end end end
return resend
function p.board(frame) local args = frame.args local pargs = frame:getParent.args local size = (args.size or pargs.size) or '26' local reverse = (args.reverse or pargs.reverse or ):lower
"true" local lightdark = (args.lightdark or pargs.lightdark or ):lower
"true" local fen = args.fen or pargs.fen
size = mw.ustring.match(size, '[%d]+') or '26' -- remove px from size if (fen) then align = (args.align or pargs.align or 'tright'):lower clear = (args.clear or pargs.clear) or (align:match('tright') and 'right' or 'none') header = args.header or pargs.header or footer = args.footer or pargs.footer or return chessboard(convertFenToArgs(fen), size, rows, cols, reverse, trans, lightdark, altprefix, letters, numbers, header, footer, align, clear, noframe) end if args[3] then return chessboard(args, size, rows, cols, reverse, trans, lightdark, altprefix, letters, numbers, header, footer, align, clear, noframe) else return chessboard(pargs, size, rows, cols, reverse, trans, lightdark, altprefix, letters, numbers, header, footer, align, clear, noframe) end end
return p