Struct alcibiades::utils::MoveStack
[−]
[src]
pub struct MoveStack { /* fields omitted */ }
Stores a list of moves for each position in a given line of play.
Examples:
let mut s = MoveStack::new(); assert_eq!(s.ply(), 0); assert_eq!(s.list().len(), 0); s.push(Move::invalid()); s.push(Move::invalid()); assert_eq!(s.list().len(), 2); let first_move = s.pull_best(); assert_eq!(s.list().len(), 1); s.save(); assert_eq!(s.ply(), 1); assert_eq!(s.list().len(), 0); s.restore(); assert_eq!(s.ply(), 0); assert_eq!(s.list().len(), 1); let second_move = s.pull_best(); assert_eq!(s.list().len(), 0);
Methods
impl MoveStack
[src]
fn new() -> MoveStack
Creates a new (empty) instance.
fn save(&mut self)
Saves the current move list and replaces it with an empty one.
This method can be called many times. At each call the current
move list will be saved to the stack of lists that can later
be restored. After calling save
the new current move list
will be empty.
fn restore(&mut self)
Restores the last saved move list.
The current move list is lost.
Panics
Panics if there are no saved move lists left.
fn ply(&self) -> usize
Returns the number of saved move lists.
The number of saved move lists starts at zero. It is
incremented on each call to save
, and decremented on each
call to restore
.
fn clear(&mut self)
Clears the current move list, removing all moves from it.
fn clear_all(&mut self)
Clears the current move list and deletes all saved move lists.
fn push(&mut self, m: Move)
Appends a move to the end of the current move list.
fn pop(&mut self) -> Option<Move>
Removes the last move from the current move list and returns it.
If the current move list is empty, None
is returned.
fn pull(&mut self, index: usize) -> Move
Removes the move at given index from the current move list and returns it.
Move's slot is taken by the last move in the current list, and the last slot is discarded.
Panics
Panics if there is no move at the given index.
fn pull_move(&mut self, move_digest: MoveDigest) -> Option<Move>
Removes a specific move from the current move list and returns it.
This method tries to find a move m
for which m.digest() == move_digest
. If such move is found, Some(m)
is returned,
move's slot is taken by the last move in the current list, and
the last slot is discarded. If no such move is found, None
is returned.
fn pull_best(&mut self) -> Option<Move>
Removes the move with the highest value from the current move list and returns it.
Best move's slot is taken by the last move in the current
list, and the last slot is discarded. None
is returned if
the current move list is empty.
fn list(&self) -> &[Move]
Returns the current move list as a slice.
fn list_mut(&mut self) -> &mut [Move]
Returns the current move list as a mutable slice.