Struct jja::abkbook::AbkBook

source ·
pub struct AbkBook {
Show 13 fields pub author: String, pub comment: String, pub book_depth: u32, pub book_moves: u32, pub moves: Vec<SBookMoveEntry>, pub min_games: u32, pub min_wins: u32, pub win_percent_white: u32, pub win_percent_black: u32, pub probability_priority: u32, pub probability_games: u32, pub probability_win_percent: u32, pub use_book_half_move: u32, /* private fields */
}
Expand description

AbkBook is a reader for the ABK format used for opening books in chess engines.

The struct contains the author, a comment, the depth of the book, the number of moves in the book, the raw book data, and a list of move entries.

Fields§

§author: String

The author of the opening book.

§comment: String

A comment about the opening book.

§book_depth: u32

The depth of the book, measured in ply.

§book_moves: u32

The total number of moves in the book.

§moves: Vec<SBookMoveEntry>

A list of move entries in the book.

§min_games: u32

The minimum number of games for moves in the opening book.

§min_wins: u32

The minimum number of wins for moves in the opening book.

§win_percent_white: u32

The win percentage for white in the opening book.

§win_percent_black: u32

The win percentage for black in the opening book.

§probability_priority: u32

The priority probability used for move selection in the opening book.

§probability_games: u32

The number of games probability used for move selection in the opening book.

§probability_win_percent: u32

The win percentage probability used for move selection in the opening book.

§use_book_half_move: u32

The maximum half move depth the book can be used for.

Implementations§

source§

impl AbkBook

source

pub fn new() -> Self

Creates a new AbkBook instance.

Initializes an AbkBook with default values, such as empty author and comment strings, zero book depth, zero book moves, empty book and moves vectors, zero minimum games, zero minimum wins, and zero win percentages for both white and black players.

Returns
  • AbkBook - A new AbkBook instance with default values.
source

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

Reads an ABK file and populates the fields of the AbkBook instance.

Arguments
  • file_name - A file path reference to the ABK file to be read.
Errors

Returns an error if the file cannot be opened or read.

source

pub fn write_file<W: Seek + Write>( &mut self, file: &mut BufWriter<W>, progress_bar: Option<&ProgressBar> ) -> Result<()>

Writes the AbkBook instance to an ABK file.

Arguments
  • file - A mutable reference to a BufWriter instance.
  • progress_bar - An optional progress bar to report progress.
Errors

Returns an error if the file cannot be created or written to.

source

pub fn total_entries(&self) -> usize

Returns the total number of entries in the ABK opening book.

Returns

A usize containing the number of entries. Note, this function returns zero if the ABK opening book file is not memory mapped.

source

pub fn lookup_moves( &self, position: &Chess, progress_bar: Option<&ProgressBar> ) -> Option<Vec<SBookMoveEntry>>

Looks up moves from the book for a given position.

Arguments
  • position - A reference to a Chess position.
  • progress_bar - An optional progress bar to report progress.
Returns

Returns an Option containing a Vec of SBookMoveEntry for the given position, or None if no moves are found.

source

pub fn write_pgn( &mut self, output: &mut dyn Write, position: &Chess, event: &str, site: &str, date: &str, white: &str, black: &str, result: &str, max_ply: usize, progress_bar: Option<&ProgressBar> )

Writes all possible games contained in an Arena opening book to a PGN file.

This function traverses the Arena 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 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, progress_bar: Option<&ProgressBar> ) -> Tree<String>

Constructs a tree from the AbkBook instance, starting from the given position and up to the specified max_ply.

Arguments
  • position: &Chess - The starting position for the tree.
  • max_ply: u16 - The maximum depth of the tree.
  • progress_bar: Option<&ProgressBar> - An optional progress bar to report progress.
Returns
  • A Tree<String> containing a tree of moves.
source

pub fn traverse_book_and_merge( &mut self, pos: &Chess, moves: &mut BTreeMap<u64, Vec<CompactSBookMoveEntry>>, progress_bar: Option<&ProgressBar> )

Traverses the book and merges the moves in the AbkBook instance.

Arguments
  • pos: &Chess - The starting position for the traversal.
  • moves: &mut BTreeMap<u64, Vec<CompactSBookMoveEntry>> - The btree map of moves to merge.
  • progress_bar: Option<&ProgressBar> - An optional progress bar to report progress.
source

pub fn traverse_book( &mut self, progress_bar: Option<&ProgressBar> ) -> BTreeMap<u64, Vec<SBookMoveEntry>>

Traverses the book and builds a HashMap with the Zobrist hash of the position as the key and the corresponding moves as the value.

Arguments
  • progress_bar: Option<&ProgressBar>: An optional progress bar to report progress.
Returns

Returns a BTreeMap containing the Zobrist hash of positions and their corresponding moves.

source

pub fn sort_entries(&self, entries: &mut [CompactSBookMoveEntry])

Sorts the given slice of SBookMoveEntry instances based on their priority and the weighted score.

Arguments
  • entries: &mut [SBookMoveEntry] - The mutable slice of SBookMoveEntry instances to be sorted.

Trait Implementations§

source§

impl Debug for AbkBook

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for AbkBook

source§

fn default() -> Self

Returns the “default value” for a type. 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