Uppercase letters are used to represent white pieces, lowercase black. Squares on the chessboard are identified with the standard algebraic notation of a (lowercase) letter a-h followed by a number 1-8, which represent file (column) and rank (row) respectively, with 1 being the white home rank and 8 being black. The default state of the chessboard is:
. . a b c d e f g h . .
. +-----------------....+ .
8 | r n b q k b n r ...| 8
7 | p p p p p p p p. | 7
6 | . . . . . . . .......... | 6
5 | . . . . . . . . .........| 5
4 | . . . . . . . . .........| 4
3 | . . . . . . . . .........| 3
2 | P P P P P P P P .| 2
1 | R N B Q K B N R | 1
. +-----------------+ .
. . a b c d e f g h . .
Usage
The chest.py test program demonstrates the general way the module is intended to be used. The constants WHITE and BLACK are used to indicate colors. Create a Game instance, call its move method with names, which returns instances of a Move class to indicate the state of the resulting move, and raises errors on encountering problems. The ok method indicates whether or not the game is over.
Notation
The move disambiguator is somewhat sophisticated and understands a variety of notation types:
algebraic notation (AN)
The most widely used of simple chess notations, simply consisting of two algebraic locations indicating a starting square and an ending square; e.g., d2d4, g1f3, d5e6.
long algebraic notation (LAN)
Extended algebraic, including an intervening - for moves and x for piece captures, as well as a preceding (uppercase, regardless of color) piece type; e.g., Pd2-d4, Ng1-f3, Pd5xe6.
standard algebraic notation (SAN)
As described by the Portable Game Notation (PGN). A full specification is available, but the key features are as follows:
Non-capturing moves generally involve only the piece type and the destination square, where pawns are generally not listed; e.g., d4, Nf3, Qd6. When disambiguation of moves is necessary, the file of the desired piece should be indicated; e.g., Nce2, Raf1.
Captures are indicated with by putting an x between the piece type and the destination square; for pawns, the file of the capturing piece is used; e.g., fxg6, Qxa5. When further disambiguation is necessary, full algebraic notation may be used; e.g., Qc3xa5.
Kingside castle is indicated with O-O, queenside with O-O-O.
A suffixed + indicates check, a suffixed # indicates checkmate.
A = followed by a piece name indicates pawn promotion (pawn promotion indicator comes before check or checkmate indicator, if appropriate).