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

source

pub fn open<P: AsRef<Path>>(file_name: P) -> Result<Self, Error>

Opens a Polyglot opening book file.

Arguments
  • file_name - The path to the opening book file.
Returns
  • Result<Self, Error> - Returns a Result containing a PolyGlotBook instance if successful, or an error if there was an issue opening the file.
source

pub fn into_iter_grouped(&self) -> PolyGlotBookGroupIter<'_>

Returns an iterator which iterates over entries grouped by key.

source

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 an Option with a vector of BookEntry instances representing the possible moves if found, or None if no moves or book are found.
source

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.

source

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.

source

pub fn find(&self, target_key: u64) -> Option<usize>

Helper function to find the index of the first book entry matching a target key.

Arguments
  • target_key: u64 - The target key to find in the book.
Returns
  • Option<usize> - Returns an Option with the index of the first book entry with a matching key if found, or None if no match is found.
source

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 an Option<BookEntry> instance. If the index is not smaller than the total number of entries in the book, or if the book is of zero-size, this function will return None.
source

pub fn get_key(&self, index: usize) -> Option<u64>

Helper function to read a book entry key from the opening book file.

Arguments
  • index: usize - The index of the book entry to read.
Returns
  • Option<u64> - Returns an Option with an u64 which represents the book key. If the book is not loaded or the index is out of bounds, returns None.

Trait Implementations§

source§

impl<'a> IntoIterator for &'a mut PolyGlotBook

§

type Item = BookEntry

The type of the elements being iterated over.
§

type IntoIter = PolyGlotBookIter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V