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
local index =
local piece = "" -- Piece can also
local length =
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
else
-- If number not found, look for a letter (piece on board)
if piece ~= nil and piece:len() > 0 then
index = index + piece:len()
-- l: White (light); d: Black (dark)
piece = piece:lower()▼
table.insert(res, piece .. color)
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
|