fen.lua - This module manipulates FEN files.
local FEN = require 'chess.fen' french = 'rnbqkbnr/ppp2ppp/4p3/3p4/3PP3//PPP2PPP/RNBQKNR w KQkq - 0 3' newfen = FEN.fenstr_move(french, 'Nc3') print(newfen) print(FEN.fenstr2asciidiag(newfen)) f = FEN.fenstr2tab(french) print(FEN.fentab2str(f))
This module manipulates chess positions in FEN notation.
It is used by pgn2eco to look for positions
/home/eco/ECOMast.txt and report their ECO numbers,
by keeping a fenstr==>eco database of positions and their ECO numbers.
pgn2eco can be used, for example, to find the ECO
numbers corresponding to positions that arise in opening-repertoire books.
This returns a multi-line string documenting the FEN notation.
This accepts a position in FEN format and returns a multiline string which can be printed on
This accepts a position in FEN format, and an individual move in PGN syntax, then applies the move to the position and returns the resulting FEN string.
This accepts a position in FEN format, and returns a somewhat simplified version of it. Specifically, the move-number and the fifty-move-number are ommitted, and the enpassant square is reset to '-' if there is no opposing pawn available to capture on that square.
The returned string can be used as a key to index the position
in a database, for example of opening variations or endgame positions,
where it matters not if the position has arisen after 9 moves or after 8
(eg: the Sveshnikov) or has arisen by
1.d4 f5 2.g3 or by
1.g3 f5 2.d4
This accepts a game, or segment of a game, in PGN notation, and returns an array of the moves.
This splits a FEN string into a table of its fields, and returns the table. These table values are all strings; their keys are
'postab', 'active', 'castling', 'enpassant', 'fiftymove', 'movenum'
The key called
'postab' splits the position-string into a 2D array of the squares of the position. Both the rank index and the column index are numbers:
This performs the reverse conversion, returning the FEN string. During this conversion, the contents of the
fentab['postab'] are converted back into position-string.
A FEN record contains six fields.
The separator between fields is a space. The fields are:
This module is available as a luarock and should be installed by
luarocks install chess-fen
luarocks install lgdbm
20180908 1.4 fenstr_move() allows +?! 20180901 1.3 fenstr_move() reports impossible moves better 20180408 1.2 first released version 20180407 1.1 add fenstr2key() 20180315 1.0 initial prototype
Peter J Billam, http://www.pjb.com.au/comp/contact.html