Polyglot opening book reading¶
-
chess.polyglot.
open_reader
(path)¶ Creates a reader for the file at the given path.
>>> with open_reader("data/polyglot/performance.bin") as reader: ... for entry in reader.find_all(board): ... print(entry.move(), entry.weight, entry.learn) e2e4 1 0 d2d4 1 0 c2c4 1 0
-
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.
-
-
class
chess.polyglot.
MemoryMappedReader
(filename)¶ Maps a polyglot opening book to memory.
-
close
()¶ Closes the reader.
-
find_all
(board, minimum_weight=1, exclude_moves=())¶ Seeks a specific position and yields corresponding entries.
-
find
(board, minimum_weight=1, exclude_moves=())¶ Finds the main entry for the given position or zobrist hash.
The main entry is the first entry with the highest weight.
By default entries with weight
0
are excluded. This is a common way to delete entries from an opening book without compacting it. Pass minimum_weight0
to select all entries.Raises
IndexError
if no entries are found.
-
choice
(board, minimum_weight=1, exclude_moves=(), random=<module 'random' from '/home/docs/checkouts/readthedocs.org/user_builds/python-chess/envs/v0.15.4/lib/python3.4/random.py'>)¶ Uniformly selects a random entry for the given position.
Raises
IndexError
if no entries are found.
-
weighted_choice
(board, exclude_moves=(), random=<module 'random' from '/home/docs/checkouts/readthedocs.org/user_builds/python-chess/envs/v0.15.4/lib/python3.4/random.py'>)¶ Selects a random entry for the given position, distributed by the weights of the entries.
Raises
IndexError
if no entries are found.
-
-
chess.
POLYGLOT_RANDOM_ARRAY
= [0x9D39247E33776D41, ..., 0xF8D626AAAF278509]¶ Array of 781 polyglot compatible pseudo random values for Zobrist hashing.