This template is within the scope of WikiProject Chess, a collaborative effort to improve the coverage of Chess on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.ChessWikipedia:WikiProject ChessTemplate:WikiProject Chesschess articles
This page has archives.Sections older than 90 daysmay be automatically archived by Lowercase sigmabot IIIwhen more than 4 sections are present.
Another pull request: Add multi-digit support to FEN
Since the FEN parsing code in Module:Chessboard mxn is clean and allows for fairy pieces, the only thing stopping us from using this code to have large board chess variant support a lack of support for multi-digit numbers in the FEN converter. I have fixed this.
Here’s the current code (lines 130-152):
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 res
end
Here’s my updated version of that code with support for multi-character numbers (which are used in, say, Fairy Stockfish), over at Module:Chessboard_mxn/Sandbox so that we can have standard large board Fairy chess FEN like rnbqkcabnr/pppppppppp/10/10/10/10/PPPPPPPPPP/RNBQKCABNR (lines 130-171 in the “Sandbox” module):
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
srow = srow:gsub("/","") -- clean up row
-- Loop over all letters and numbers in the row
-- Since Lua regexes do not have the | operator, we have
-- to spell things out
local index = 1
local piece = "" -- Piece can also be empty squares
local place = 0
local pstart = 0
local pend = 0
local length = srow:len()
while index <= length do
-- Look for a number. Can have multiple digits
pstart, pend = srow:find("%d+", index)
if pstart == index then
piece = srow:sub(pstart, pend)
index = pend + 1
for k=1,tonumber(piece) do
table.insert(res,' ')
end
else
-- If number not found, look for a letter (piece on board)
pstart = srow:find("%a",index)
if pstart == index then
piece = srow:sub(pstart, pstart)
index = pstart + 1
-- l: White (light); d: Black (dark)
local color = piece:match( '%u' ) and 'l' or 'd'
piece = piece:lower()
table.insert(res, piece .. color)
else
index = length + 1 -- Break loop
end
end
end
end
return res
end
Some thoughts on the coding style:
I avoid Lua’s coercion with an explicit “tonumber()” call. This isn’t needed in Lua, but I have it here so that other programmers know I meant to make that string a number
There’s some infinite loop protection, which is needed for code which runs on a “mainframe” like Wikimedia’s servers: We will always increase “index”, no matter what is in the string.
Lua doesn’t have an | operator in its regex library. This is by design; if you have ever seen how big the Lua port of a pcre library is, we can make the loop a little bigger to keep the regex library small. (Speaking of pcre, I once had dinner with Larry Wall)
I'm looking at the various chess pieces that this template uses, and they appear to be released under CC BY-SA 3.0. That's perfectly fine for using, but we'd need to maintain some way to give the creators of those pieces attribution for their artwork. Some of these pieces are not trivially simple as to be in the public domain by virtue of their simplicity—particularly so for fairy chess pieces like the elephant. The standard way to do this is by linking to the source material for the various images that are used, but the template currently makes it so that clicking on a piece does not take one into the mediaviewer. For reasons of copyright, I think this probably should be changed, and I'm opening up discussion here towards that end. — Red-tailedhawk(nest) 14:37, 1 November 2023 (UTC)
Can we please add a CSS class of "notheme" to the output of Module:Chessboard, in addition to the "chess-board" class? This will help prevent issues with styling in Dark themes in mobile apps, and will not impact presentation otherwise. (phab:T284327) Dmitry Brant (talk) 13:42, 26 January 2024 (UTC)
I propose adding a black border around the white marking symbols. As it is, they kinda blend in when placed on a light square. I have to imagine that that was why the white piece symbols were given black borders, so we might as well do it here, too.
Can we get a third type of marking, the ring? It's like the dot, but it has a circular bit missing inside. You use "oO" and "xO" for the white ring and black ring, respectively. It'd be nice to standardize using the ring to indicate non-capturing moves, which applies to the pawn and to many fairy chess pieces. Plus, having a third colored symbol might also come in handy elsewhere (e.g., that one diagram in Castling §History, where we could really use a symbol to fill in the squares given by H. J. R. Murray).