Struct jja::polyglotbook::PolyGlotBook
source · pub struct PolyGlotBook {
pub num_entries: usize,
/* private fields */
}
Expand description
PolyGlotBook
is a struct that represents a Polyglot opening book.
Fields§
§num_entries: usize
The number of entries in the Polyglot opening book.
Implementations§
source§impl PolyGlotBook
impl PolyGlotBook
sourcepub fn into_iter_grouped(&self) -> PolyGlotBookGroupIter<'_> ⓘ
pub fn into_iter_grouped(&self) -> PolyGlotBookGroupIter<'_> ⓘ
Returns an iterator which iterates over entries grouped by key.
sourcepub fn lookup_moves(&self, key: u64) -> Option<Vec<BookEntry>>
pub fn lookup_moves(&self, key: u64) -> Option<Vec<BookEntry>>
Looks up the moves available in the opening book for the given chess position.
Arguments
key: u64
- Zobrist hash of the chess position to look up.
Returns
Option<Vec<BookEntry>>
- Returns anOption
with a vector ofBookEntry
instances representing the possible moves if found, orNone
if no moves or book are found.
sourcepub fn write_pgn(
&self,
output: &mut dyn Write,
position: &Chess,
event: &str,
site: &str,
date: &str,
white: &str,
black: &str,
result: &str,
look_ahead: usize,
max_ply: usize,
progress_bar: Option<&ProgressBar>
)
pub fn write_pgn( &self, output: &mut dyn Write, position: &Chess, event: &str, site: &str, date: &str, white: &str, black: &str, result: &str, look_ahead: usize, max_ply: usize, progress_bar: Option<&ProgressBar> )
Writes all possible games contained in a Polyglot book to a PGN file.
This function traverses the Polyglot book, which is a type of opening book, and writes all possible games to the output file in PGN format. A game is considered “possible” if it follows a path of moves in the book from the given starting position to a position with no more book moves. Each game is written as a separate round, and the rounds are numbered consecutively starting from 1.
The output
argument is a mutable reference to a Write
trait object where the generated PGN will be written.
The event
, site
, date
, white
, black
, and result
arguments are used to fill in the corresponding PGN tags for each game.
The look_ahead
argument determines how many number of plies to look ahead on book lookup
misses. This is useful to create PGN out of books created with --only-black
or
only-white
(currently only 0 and 1 are implemented, panics on other values).
The max_ply
argument determines the limit of variation depth in plies.
The progress_bar
is an optional reference to a progress bar to report progress.
Errors
This function will panic if writing to the output file fails.
Panics
Panics if the disk is full or the file isn’t writable.
sourcepub fn tree(&self, position: &Chess, max_ply: u16) -> Tree<String>
pub fn tree(&self, position: &Chess, max_ply: u16) -> Tree<String>
A method that generates a tree of moves from a given position using an opening book.
sourcepub fn get(&self, index: usize) -> Option<BookEntry>
pub fn get(&self, index: usize) -> Option<BookEntry>
Helper function to get a book entry from the opening book file.
Arguments
index: usize
- The index of the book entry to get.
Returns
Option<BookEntry>
- Returns anOption<BookEntry>
instance. If theindex
is not smaller than the total number of entries in the book, or if the book is of zero-size, this function will returnNone
.