|
Cute Chess
0.1
|
A collection of opening moves for chess. More...
#include <openingbook.h>
Classes | |
| struct | Entry |
| An entry in the opening book. More... | |
Public Types | |
| enum | AccessMode { Ram, Disk } |
Public Member Functions | |
| QList< Entry > | entries (quint64 key) const |
| int | import (const PgnGame &pgn, int maxMoves) |
| int | import (PgnStream &in, int maxMoves) |
| Chess::GenericMove | move (quint64 key) const |
| OpeningBook (AccessMode mode=Ram) | |
| bool | read (const QString &filename) |
| bool | write (const QString &filename) const |
| virtual | ~OpeningBook () |
Protected Types | |
| typedef QMultiMap< quint64, Entry > | Map |
Protected Member Functions | |
| void | addEntry (const Entry &entry, quint64 key) |
| virtual int | entrySize () const =0 |
| virtual Entry | readEntry (QDataStream &in, quint64 *key) const =0 |
| virtual void | writeEntry (const Map::const_iterator &it, QDataStream &out) const =0 |
Friends | |
| LIB_EXPORT QDataStream & | operator<< (QDataStream &out, const OpeningBook *book) |
| LIB_EXPORT QDataStream & | operator>> (QDataStream &in, OpeningBook *book) |
A collection of opening moves for chess.
OpeningBook is a container (binary tree) class for opening moves that can be played by the GUI. When the game goes "out of book", control of the game is transferred to the players.
The opening book can be stored externally in a binary file. When it's needed, it is loaded in memory, and positions can be found quickly by searching the book for Zobrist keys that match the current board position.
|
protected |
The type of binary tree.
| OpeningBook::OpeningBook | ( | AccessMode | mode = Ram | ) |
Creates a new OpeningBook with access mode mode.
|
virtual |
Destroys the opening book.
|
protected |
Adds a new entry to the book.
| QList< OpeningBook::Entry > OpeningBook::entries | ( | quint64 | key | ) | const |
Returns all entries matching key.
|
protectedpure virtual |
Returns the book format's internal entry size in bytes.
Implemented in PolyglotBook.
| int OpeningBook::import | ( | const PgnGame & | pgn, |
| int | maxMoves | ||
| ) |
Imports a PGN game.
| pgn | The game to import. |
| maxMoves | The maximum number of halfmoves that can be imported. |
Returns the number of moves imported.
| int OpeningBook::import | ( | PgnStream & | in, |
| int | maxMoves | ||
| ) |
Imports PGN games from a stream.
| in | The PGN stream that contains the games. |
| maxMoves | The maximum number of halfmoves per game that can be imported. |
Returns the number of moves imported.
| Chess::GenericMove OpeningBook::move | ( | quint64 | key | ) | const |
Returns a move that can be played in a position where the Zobrist key is key.
If no matching moves are found, an empty (illegal) move is returned.
If there are multiple matches, a random, weighted move is returned. Popular moves have a higher probablity of being selected than unpopular ones.
| bool OpeningBook::read | ( | const QString & | filename | ) |
Reads a book from filename. Returns true if successful; otherwise returns false.
|
protectedpure virtual |
Reads a new book entry from in and returns it.
The implementation must set key to the hash that belongs to the entry.
Implemented in PolyglotBook.
| bool OpeningBook::write | ( | const QString & | filename | ) | const |
Writes the book to filename. Returns true if successful; otherwise returns false.
|
protectedpure virtual |
Writes the key and entry pointed to by it, to out.
Implemented in PolyglotBook.
|
friend |
Writes a book to a data stream.
|
friend |
Reads a book from a data stream.
1.8.11