Module:Chessboard
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module uses TemplateStyles: |
Implements {{Chess diagram}}.
Usage
{{#invoke:Chessboard|function_name}}
local p = {}
p.f = function(frame)
local fen,size,reverse
function coord(ind)
return (reverse and (7 - ind) * size) or ind * size
end
function colBool(bool)
return (bool and 'l') or 'd'
end
function piecepict(file,row,piece)
local squareColor = colBool( (file + row) % 2 == 0 )
local pieceColor = colBool(piece == string.upper(piece))
return string.format('[[File:Chess %s%st45.svg|%dx%dpx|link=]]', string.lower(piece), pieceColor, size, size)
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 .. string.format('<div style="top:%dpx;left:%dpx;">%s</div>\n', coord(row), coord(file), piecepict(file,row,piece))
file = file + 1
end
end
return result
end
local row = 0;
fen = frame.args['fen']
size = frame.args['size'] or 30
reverse = string.lower(frame.args['reverse'] or '') == "true"
local result = string.format('<div class="chess-fen" style="min-width:%dpx;min-height:%dpx;">', size*8,size*8)
result = result .. string.format('<div style="z-index:0; top:0px; left:0px;">[[File:Chessboard480.png|%dx%dpx]]</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