Modul:Schachbrett
Erscheinungsbild
Die Dokumentation für dieses Modul kann unter Modul:Schachbrett/Doku erstellt werden
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 rownumFromRow(row)
return "reverse: " .. tostring(reverse) .. ' ' .. ((reverse and (row + 1)) or (8 - row))
end
function filecharFromFile(file)
mfile = (reverse and (8 - file)) or (file + 1)
return " reverse: " .. tostring(reverse) .. ' mfile:' .. mfile .. string.sub("abcdefgh", mfile, mfile) .. ' '
end
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 alt = string.format("%s%s %s %s", filecharFromFile(file), rownumFromRow(row), p.colornames[pieceColor], p.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 = ''
for piece in string.gmatch(s, "%\w") do
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)
result = result .. string.format('<div style="position:absolute;z-index:0; top:0px; left:0px;">[[File:Chessboard480.png|%dx%dpx|link=]]</div>', size * 8, size * 8)
for srow in string.gmatch("/" .. fen, "/%w+") do
result = result .. oneRow(srow, row)
row = row + 1
end
result = result .. '</div>'
return result
end
return p