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§
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
impl AbkBook
sourcepub fn new() -> Self
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 newAbkBook
instance with default values.
sourcepub fn write_file<W: Seek + Write>(
&mut self,
file: &mut BufWriter<W>,
progress_bar: Option<&ProgressBar>
) -> Result<()>
pub fn write_file<W: Seek + Write>( &mut self, file: &mut BufWriter<W>, progress_bar: Option<&ProgressBar> ) -> Result<()>
sourcepub fn total_entries(&self) -> usize
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.
sourcepub fn lookup_moves(
&self,
position: &Chess,
progress_bar: Option<&ProgressBar>
) -> Option<Vec<SBookMoveEntry>>
pub fn lookup_moves( &self, position: &Chess, progress_bar: Option<&ProgressBar> ) -> Option<Vec<SBookMoveEntry>>
sourcepub 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>
)
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.
sourcepub fn tree(
&self,
position: &Chess,
max_ply: u16,
progress_bar: Option<&ProgressBar>
) -> Tree<String>
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.
sourcepub fn traverse_book_and_merge(
&mut self,
pos: &Chess,
moves: &mut BTreeMap<u64, Vec<CompactSBookMoveEntry>>,
progress_bar: Option<&ProgressBar>
)
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.
sourcepub fn traverse_book(
&mut self,
progress_bar: Option<&ProgressBar>
) -> BTreeMap<u64, Vec<SBookMoveEntry>>
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.
sourcepub fn sort_entries(&self, entries: &mut [CompactSBookMoveEntry])
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 ofSBookMoveEntry
instances to be sorted.