Chess::PGN::Parse

Chess::PGN::Parse is a Perl module that reads and parses PGN (Portable Game Notation) Chess files.
Download

Chess::PGN::Parse Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Giuseppe Maxia
  • Publisher web site:
  • http://search.cpan.org/~gmax/Chess-PGN-Parse-0.19/Parse.pm

Chess::PGN::Parse Tags


Chess::PGN::Parse Description

Chess::PGN::Parse is a Perl module that reads and parses PGN (Portable Game Notation) Chess files. Chess::PGN::Parse is a Perl module that reads and parses PGN (Portable Game Notation) Chess files.SYNOPSIS use Chess::PGN::Parse; use English qw( -no_match_vars ); my $pgnfile = "kk_2001.pgn"; my $pgn = new Chess::PGN::Parse $pgnfile or die "can't open $pgnfilen"; while ($pgn->read_game()) { print $pgn->white, ", " , $pgn->black, ", ", $pgn->result, ", ", $pgn->game, "n"; } use Chess::PGN::Parse; my $text =""; { local $INPUT_RECORD_SEPARATOR = undef; open PGN "< $pgnfile" or die; $text = ; close $text; } # reads from string instead of a file my $pgn = new Chess::PGN::Parse undef, $text; while ($pgn->read_game()) { print $pgn->white, ", " , $pgn->black, ", ", $pgn->result, ", ", $pgn->game, "n"; } use Chess::PGN::Parse; my $pgnfile = "kk_2001.pgn"; my $pgn = new Chess::PGN::Parse $pgnfile or die "can't open $pgnfilen"; my @games = $pgn->smart_read_all();Chess::PGN::Parse offers a range of methods to read and manipulate Portable Game Notation files. PGN files contain chess games produced by chess programs following a standard format (http://www.schachprobleme.de/chessml/faq/pgn/). It is among the preferred means of chess games distribution. Being a public, well established standard, PGN is understood by many chess archive programs. Parsing simple PGN files is not difficult. However, dealing with some of the intricacies of the Standard is less than trivial. This module offers a clean handle toward reading and parsing complex PGN files.A PGN file has several tags, which are key/values pairs at the header of each game, in the format After the header, the game follows. A string of numbered chess moves, optionally interrupted by braced comments and recursive parenthesized variants and comments. While dealing with simple braced comments is straightforward, parsing nested comments can give you more than a headache.Chess::PGN::Parse most immediate methods are: read_game() reads one game, separating the tags and the game text. parse_game() parse the current game, and stores the moves into an array and optionally saves the comments into an array of hashes for furter usage. It can deal with nested comments and recursive variations. quick_parse_game() Same as the above, but doesn't save the comments, which are just stripped from the text. It can't deal with nested comments. Should be the preferred method when we know that we are dealing with simple PGNs. smart_parse_game() Best of the above methods. A preliminary check will call parse_game() or quick_parse_game(), depending on the presence of nested comments in the game. read_all(), quick_read_all(), smart_read_all() will read all the records in the current PGN file and return an array of hashes with all the parsed details from the games.Requirements:· Perl


Chess::PGN::Parse Related Software