Deze module is nog in ontwikkeling (versie 0.0) en wordt getest.
De Module:Layout is bedoeld om snel, consistent en uitgebreid een pagina op te maken.
Er is een op de module afgestemde handleiding over deze onderwijswiki beschikbaar.
localcontent={};localCHESS={};CHESS.LETTERS_WHITE={"a","b","c","d","e","f","g","h"};CHESS.LETTERS_BLACK={"h","g","f","e","d","c","b","a"};CHESS.RANK={a="",b="",c="",d="",e="",f="",g="",h=""};functioncontent.main(call)-- The functions from other modules that are used in this functionlocalarray=call.include("array");localchessboard_ranks={};-- to store the rankslocalchessboard_files=nil;-- to store the definition of the files and their order, if not given by the user it is filled anyway by the default setup based on the first ranknumber specifiedlocalletter_position=1;-- Check every unnamed parameter to obtain information about the boardfori,vinipairs(call.unnamed)do-- every rank starts with the row number localranknumber=tonumber(v);-- Check if the parameter is a valid rank numberifranknumber~=nilandranknumber>=1andranknumber<=8then-- The 8 follwing unnamed parameters should be defining board squares of that rankchessboard_ranks[ranknumber]=array.slice(call.unnamed,i+1,i+8);-- Check if this is the first number and if so initialze the file definition based on this numberifchessboard_files==nilthenifranknumber==1thenchessboard_files=CHESS.LETTERS_BLACK;elsechessboard_files=CHESS.LETTERS_WHITE;endendend-- Check if the parameter is a valid file letter and then overwrite the default definition of the filesifarray.search(CHESS.LETTERS_WHITE,v)andletter_position<=8thenchessboard_files[letter_position]=v;letter_position=letter_position+1;endendlocalchessboard_matrix={};-- Initialize the squares with empty values so we get a full matrix;fori=1,8dochessboard_matrix[i]={a="",b="",c="",d="",e="",f="",g="",h=""};end-- Now fill from the ranks and the file definition the matrixfori,vinipairs(chessboard_ranks)dolocalnew_rank={};forindex,valueinipairs(v)donew_rank[chessboard_files[index]]=value;endchessboard_matrix[i]=new_rank;endlocalresult={};result.matrix=chessboard_matrix;result.CHESS=CHESS;call.content=result;returncall;endfunctioncontent.PGNtoFEN(pgn)-- Set up the initial positionlocalboard={}fori=1,8doboard[i]={}forj=1,8doboard[i][j]=" "endend-- Parse the PGN moveslocalmoves={}formoveinpgn:gmatch("%S+")doifmove:sub(1,1)~="["thentable.insert(moves,move)endend-- Apply the moves to the boardfori,moveinipairs(moves)do-- Parse the movelocalfromFile,fromRank,toFile,toRank=move:match("(%a)(%d)(%a)(%d)")localpiece=move:sub(1,1)ifpiece=="N"thenpiece="knight"elseifpiece=="B"thenpiece="bishop"elseifpiece=="R"thenpiece="rook"elseifpiece=="Q"thenpiece="queen"elseifpiece=="K"thenpiece="king"end-- Apply the move to the boardboard[tonumber(fromRank)][fromFile:byte()-96]=" "board[tonumber(toRank)][toFile:byte()-96]=pieceend-- Convert the board to FENlocalfen=""fori=8,1,-1dolocalemptySquares=0forj=1,8dolocalsquare=board[i][j]ifsquare==" "thenemptySquares=emptySquares+1elseifemptySquares>0thenfen=fen..emptySquaresemptySquares=0endifsquare=="knight"thenfen=fen.."N"elsefen=fen..square:sub(1,1):upper()endendendifemptySquares>0thenfen=fen..emptySquaresendifi>1thenfen=fen.."/"endendfen=fen.." w - - 0 1"returnfenendreturncontent;