Polyglot opening book reading


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(key, raw_move, weight, learn)

An entry from a polyglot opening book.


The Zobrist hash of the position.


The raw binary representation of the move. Use the move() method to extract a move object from this.


An integer value that can be used as the weight for this entry.


Another integer value that can be used for extra information.


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)
>>> # 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 the first entry for the given position.

Raises KeyError if there are no entries for the position.


Reads the next raw entry as a tuple.

Raises StopIteration at the EOF.


Reads the next Entry.

Raises StopIteration at the EOF.


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.