Content deleted Content added
nitpicking |
No edit summary |
||
Line 35:
table.insert(result, '</div>')
return result
end
--[[
this function is to be used only from Template:Chess diagram.
it provides part of the FEN string - the part that describes the board itself.
unfortunately, the template does not carry enough information to create the 2nd
part of the FEN, which includes information about whose turn is it, en-passant state,
castling, etc.
]]
function diagramToFen( frame )
function nullOrWhitespace( s ) return not s or s:match( '^%s*(.-)%s*$' ) == '' end
function piece( s )
return nullOrWhitespace( s ) and 1
or s:gsub( '%s*(%a)(%a)%s*', function( a, b ) return b == 'l' and a:upper() or a end )
end
local args = frame:getParent().args
local res = ''
for row = 0, 7 do
for file = 0, 7 do
res = res .. piece( args[3 + row * 8 + file] )
end
if row < 7 then res = res .. '/' end
end
return ( res.gsub('1+', function( s ) return #s end ) )
end
Line 42 ⟶ 68:
local t = chessboard( args.fen, args.size or 30, ( args.reverse or '' ):lower() == "true" )
return table.concat( t, "\n" )
end,
['extract fen'] = diagramToFen,
}
|