Module:Chessboard mxn/Sandbox: Difference between revisions

Content deleted Content added
Make this a carbon copy of Module:Chessboard/Chess (we will change it in a second)
 
Rewrite FEN converter to allow multi digit numbers
Line 134:
for srow in string.gmatch("/" .. fen, "/%w+") do
-- Loop over all letters and numbers in the row
-- Since Lua regexes do not have the | operator, we have
for piece in srow:gmatch( "%w" ) do
-- to spell things if (piece:match("%d")) thenout
local index = -- if a digit1
local piece = "" -- Piece can also forbe k=1,pieceempty dosquares
local length = table.insertsrow:len(res,' ')
while index < length do
-- Look for a number. Can have multiple digits
piece = srow:match("%d+", index)
if piece ~= nil and piece:len() > 0 then
index = index + piece:len()
for k=1,tonumber(piece) do
table.insert(res,' piece .. color ')
else end
else
-- If number not found, look for a letter (piece on board)
for piece in= srow:gmatchmatch( "%wa" ,index) do
if piece ~= nil and piece:len() > 0 then
index = index + piece:len()
-- l: White (light); d: Black (dark)
local color = piece:match( '%u' ) and 'l' or 'd'
piece = piece:lower()
table.insert(res, piece .. color)
-- not a digitelse
index = length + 1 -- Break loop
end
else
-- not a digit
local color = piece:match( '%u' ) and 'l' or 'd'
piece = piece:lower()
table.insert(res, piece .. color )
end
end