Module:Chessboard: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1:
local p = {
piecenames = {p = 'Pawn', r = 'Rook', n = 'Knight', b = 'Bishop', q = 'Queen', k = 'King'},
colornames = { l = 'White', d = 'Black' }
}
 
p.f = function(frame)
local fen = frame.args['fen']
local size = frame.args['size'] or 30
local reverse = string.lower(frame.args['reverse'] or '') == "true"
 
function coord(ind)
return (reverse and (7 - ind) * size) or ind * size
end
 
function piecediv(piece, row, file)
local pieceColor = string.match(piece, '%u') and 'l' or 'd'
piece = string.lower(piece)
local filechar = string.sub("abcdefgh", file + 1, file + 1)
local alt = p.colornames[pieceColor] .. ' ' .. p.piecenames[piece]
local imgalt = string.format('[[File:Chess "%s%st45.svg|%dx%dpx|link=|alt=d %s| %s]]'", piecefilechar, pieceColor,row size,+ size1, altp.colornames[pieceColor], altp.piecenames[piece])
local img = string.format('[[File:Chess %s%st45.svg|%dx%dpx|alt=%s|%s]]', piece, pieceColor, size, size, alt, alt)
return string.format('<div style="position:absolute;z-index:3;top:%dpx;left:%dpx;">%s</div>\n', coord(row), coord(file), img)
end
 
function oneRow(s, row)
local file = 0
local result = ''
Line 27 ⟶ 28:
if string.match(piece, "%\d") then
file = file + piece
else
result = result .. piecediv(piece, row, file)
file = file + 1
end
end
return result
end
 
local row = 0
local result = string.format('<div class="chess-fen" style="position:relative;min-width:%dpx;min-height:%dpx;">', size*8,size*8)