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)
 
Revert: Looks like align and header already work (???)
 
(12 intermediate revisions by the same user not shown)
Line 133:
-- 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
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 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
for piece in= srow:gmatchsub(pstart, "%w" pend) do
index = pend + 1
for k=1,tonumber(piece) do
table.insert(res,' ')
end
else
-- If number not found, look for a digitletter (piece on board)
local colorpstart = piecesrow:matchfind( '"%u' a",index) and 'l' or 'd'
pieceif pstart == index piece:lower()then
table.insert(res, piece ..= colorsrow: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