Module:ChessBowserPrototype

local function build_notation_span(notation, plynum, current) local class = plynum and "pgn-movelink" or "pgn-steplink" if current then class = class .. " pgn-current-move" end local data = plynum and 'data-ply=' .. plynum or '' return string.format(' %s ', class, data, notation) end

local function move_of(notation) if not notation then return end local move = tonumber(string.sub(notation, 1, -2)) if not move then return end local col = string.sub(notation, -1) local extra = 0 if col == 'l' then extra = 1 elseif col ~= 'd' then return end return move * 2 - extra end

local function piecediv( piece, row, file, res ) local color = piece:match( '%u' ) and 'l' or 'd'	piece = piece:lower table.insert( res, string.format(' ', piece, color, 7-row, file) ) end local function pieces_of_fen(fen) local result = {} local row = 0 if not fen then return end for srow in string.gmatch("/" .. fen, "/%w+") do		local file = 0 for piece in srow:gmatch( "%w" ) do -- if a digit, increment "file" by the digit. else, add the piece _and_ increment file by 1 file = file + ( piece:match("%d") or piecediv( piece, row, file, result ) or 1 ) end row = row + 1 end return result end

local function demo(frame) local pgn = frame.args.pgn if not pgn then error('no valid pgn found') end local parser = require('Module:Parse-pgn') local fens, plys, notations, metadata = parser.parsePgn(pgn) local display_board = move_of(frame.args.display) or #fens - 1 local passToScript = { fen = fens[1], plys = plys, display = display_board, }	local baseTemp = [[		 $notations                   $pieces		 $rowLegends 		 $rowLegends 		 $fileLegends 		 $fileLegends

To see the game interactively, enable Javascript for your browser ]]	local file_letters = { [0] = "a", [1] = "b", [2] = "c", [3] = "d", [4] = "e", [5] = "f", [6] = "g", [7] = "h" } local rowlegends, filelegends = ,  for r = 0 ,7 do rowlegends = rowlegends .. ' ' .. r + 1 .. ' '		filelegends = filelegends .. ' ' .. file_letters[r] .. ' '	end local notation_spans = { build_notation_span('⚃', 0) } for i, notation in ipairs(notations) do		if i % 2 == 1 then table.insert(notation_spans, build_notation_span((i + 1) / 2 .. '.'))		end table.insert(notation_spans, build_notation_span(notation, i, i == display_board)) end local pieces = pieces_of_fen(fens[display_board + 1])

local result = string.gsub(baseTemp, '$passToScript', mw.text.jsonEncode(passToScript)) result = string.gsub(result, '$rowLegends', rowlegends) result = string.gsub(result, '$fileLegends', filelegends) result = string.gsub(result, '$notations', table.concat(notation_spans, ' ')) result = string.gsub(result, '$pieces', table.concat(pieces)) return result end

return { ['demo'] = demo, }