NAME
Chess::Opening - Perl library for handling chess openings
SYNOPSIS
die "Chess::Opening is just a documentation wrapper";
DESCRIPTION
The package Chess-Opening is a collection of modules for dealing with chess openings in Perl.
Opening Books
You can use Chess::Opening::Book::Polyglot for reading (and later writing) opening books in polyglot format.
ECO Data
You can also lookup ECO (Encyclopedia of Chess Openings) data for opening positions. See Chess::Opening::Book::ECO for more information.
You access ECO data in the same way as data from a polyglot opening book, as it is internally implemented as a Chess::Opening::Book, the base class for all opening books.
DATA FORMATS
Throughout this library, the following data formats are used:
Positions
A chess position is represented in Forsyth-Edwards Notation (FEN). This library contains no code for creating FEN strings but whatever internal representation of a chess position your code uses, it should be simple and straightforward to generate FEN strings.
If you are using Chess::Rep you can create FEN strings as follows:
$pos = Chess::Rep->new;
$pos->go_move('e4');
$fen = $pos->get_gen;
Internally, the library also uses Zobrist keys because they are used in binary polyglot opening books. The interface for generating such a Zobrist key from a FEN string may be exposed in the future if there is demand for it.
Moves
All chess moves are represented in coordinate notation. Coordinate notation uses either four (for example "g1f3") or five ("b2b1q") characters. The meaning of these characters are:
- - starting file (or column), a character between "a" and "h"
- - starting rank (or row), a digit between "1" and "8"
- - destination file (or column), a character between "a" and "h"
- - destination rank (or row), a digit between "1" and "8"
- - an optional promotion piece:
You can convert a move in coordinate notation into the popular Standard Algebraic Notation (SAN) with the help of the module Chess::Rep:
$fen = '5k2/Q7/5K2/8/8/8/8/8 w - - 0 1';
$pos = Chess::Rep->new($fen);
$move_info = $pos->go_move('Qa7-f7#');
print "SAN: $move_info->{san}\n";
The return value of Chess::Rep->go_move()
contains more useful fields with information about the move.
Chess Games
Chess games or collections of chess games are normally stored in Portable Game Notation (PGN). The Perl library Chess::PGN::Parse can be used for reading such files.
See the script parse_eco.pl that is part of Chess::Opening for an example that is using the PGN parser.
Chess-Opening itself does not use PGN at all but you will almost inevitably need it for code that is using Chess-Opening.
COPYRIGHT
Copyright (C) 2019 Guido Flohr <guido.flohr@cantanea.com>, all rights reserved.
SEE ALSO
Chess::Opening::Book, Chess::Opening::Book::Polyglot, Chess::Opening::Book::ECO, Chess::Rep, perl(1)