NAME
Chess::Pgn - Perl extension for manipulation of chess PGN format. PGN is for Portable Game Notation and follow the Portable Game Notation Specification and Implementation Guide revised 1994.03.12. You can find it at http://members.nbci.com/sghudson/standard.txt.
The goal of this module is not to play chess but to help to manipulate PGN File.
A PGN file is like this :
[Event
"?"
]
[Site
"?"
]
[Date
"????.??.??"
]
[Round
"?"
]
[White
"Greco"
]
[Black
"NN"
]
[Result
"1-0"
]
[ECO
"C57"
]
[WhiteElo
"2010"
]
[BlackElo
"1620"
]
[PlyCount
"17"
]
1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.Ng5 d5 5.exd5 Nxd5 6.Nxf7 Kxf7 7.Qf3+ Ke6
8.Nc3 Ne7 9.O-O c6 10.Re1 Bd7 11.d4 Kd6 12.Rxe5 Ng6 13.Nxd5 Nxe5
14.dxe5+ Kc5 15.Qa3+ Kxc4 16.Qd3+ Kc5 17.b4
# 1-0
[Event
"?"
]
[Site
"corr CS ch 22 (FS"
]
[Date
"????.??.??"
]
[Round
"12.0"
]
[White
"Rosenzweig V"
]
[Black
"Necesany Z"
]
[Result
"1/2-1/2"
]
[ECO
"C55"
]
[WhiteElo
"2410"
]
[BlackElo
"2620"
]
[PlyCount
"22"
]
1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.O-O Be7 5.Nc3 Nxe4 6.Nxe4 d5 7.d4 dxc4
8.d5 Nd4 9.Nxd4 Qxd5 10.Nf3 Qxe4 11.Re1 Qc6 12.Nxe5 Qf6 13.Bd2 O-O
14.Bc3 Bc5 15.Re2 Qf5 16.Qd5 Bd6 17.Rae1 Be6 18.Qxb7 f6 19.Nc6 Bd5
20.Rd2 Bxg2 21.Rxd6 Bxc6 22.Rxc6 Qg4+ 1/2-1/2
With Chess:Pgn you will find a game by $game->date or $game->game. For our last example we will have
$game
->date :
"????.??.??"
$game
->game : "1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.Ng5 d5 5.exd5 Nxd5 6.Nxf7 Kxf7 7.Qf3+ Ke6
8.Nc3 Ne7 9.O-O c6 10.Re1 Bd7 11.d4 Kd6 12.Rxe5 Ng6 13.Nxd5 Nxe5
14.dxe5+ Kc5 15.Qa3+ Kxc4 16.Qd3+ Kc5 17.b4
# 1-0"
The module provide a good set of tools to modify PGN File but you will have to make yourself the while :)
SYNOPSIS
use
Chess::Pgn;
$p
= new Chess::Pgn(
"2KTSDEF.PGN"
) ||
die
"2KTSDEF.PGN not found"
;
while
(
$p
->ReadGame )
{
$p
->white ,
"<=>"
,
$p
->black,
"\n"
;
}
$p
->quit();
$p
->white(Kouatly);
$p
->black(Kasparov);
DESCRIPTION
- new
-
$p
= new Chess::Pgn (
"name"
)
open the file name and if it doesn't exist return undef.
- ReadGame
-
$p
->ReadGame
This method read just one game and return undef at the end of file. You must use methods to read the game.
- quit
-
$p
->quit
Close the PGN file
- Basic methods
-
site, date, round, white, black, result, eco, whiteelo, blackelo, plycount, game :
return the value of the current game.
$p
->black
return
Greco
- set a value
-
You can change a value if you put a argument to the method.
For example :
$p
->black(
"Gilles Maire"
)
will change the value of the black opponent. But just in memory ! You will need to write of file to save it.
- variable
-
You can access to method value bye the hash
$p
->{Event},
$p
->{Site} ,
$p
->{Date} ,p->{Round},
$p
->{White},
$p
->{Black},
$p
->{Result},
$p
->{ECO},
$p
->{Game};
$p
->{WhiteElo},
$p
{BlackElo},
$p
->{PlyCount}
- All in One method
-
$p
->PrintAll;
return in a string all the lines concerning the current game. You can of course modify some values before call this method.
EXPORT
None by default.
AUTHOR
Gilles Maire
Gilles.Maire@ungi.net
SEE ALSO
perl(1).