Polyglot opening book reading¶
- chess.polyglot.open_reader(path)¶
Creates a reader for the file at the given path.
>>> with open_reader("data/opening-books/performance.bin") as reader: >>> entries = reader.get_entries_for_position(board)
- class chess.polyglot.Entry¶
An entry from a polyglot opening book.
- key¶
The Zobrist hash of the position.
- raw_move¶
The raw binary representation of the move. Use the move() method to extract a move object from this.
- weight¶
An integer value that can be used as the weight for this entry.
- learn¶
Another integer value that can be used for extra information.
- move()¶
Gets the move (as a Move object).
- class chess.polyglot.Reader(handle)¶
A reader for a polyglot opening book opened in binary mode. The file has to be seekable.
Provides methods to seek entries for specific positions but also ways to efficiently use the opening book like a list.
>>> # Get the number of entries >>> len(reader) 92954
>>> # Get the nth entry >>> entry = reader[n]
>>> # Iteration >>> for entry in reader: >>> pass
>>> # Backwards iteration >>> for entry in reversed(reader): >>> pass
- seek_entry(offset, whence=0)¶
Seek an entry by its index.
Translated directly to a low level seek on the binary file. whence is equivalent.
- seek_position(position)¶
Seek the first entry for the given position.
Raises KeyError if there are no entries for the position.
- next_raw()¶
Reads the next raw entry as a tuple.
Raises StopIteration at the EOF.
- next()¶
Reads the next Entry.
Raises StopIteration at the EOF.
- get_entries_for_position(position)¶
Seeks a specific position and yields all entries.
- chess.POLYGLOT_RANDOM_ARRAY = [0x9D39247E33776D41, ..., 0xF8D626AAAF278509]¶
Array of 781 polyglot compatible pseudo random values for Zobrist hashing.