Skip to main content

Reversible

Trait Reversible 

Source
pub trait Reversible: Game {
    type UndoRecord;

    // Required methods
    fn apply_undoable(
        &self,
        state: &mut Self::State,
        player: PlayerId,
        action: Self::Action,
    ) -> Self::UndoRecord;
    fn undo(&self, state: &mut Self::State, record: Self::UndoRecord);
}
Expand description

Opt-in make/unmake for games where cloning the whole state per search node is too slow (chess-scale branching).

Cloning (Game::apply_cloned) is the default and is always correct; implement this only when per-node cloning dominates the search budget. A wrong undo corrupts search silently instead of crashing, so it is a deliberate opt-in.

RNG invariant: Self::UndoRecord must capture the generator’s position as it was before the move (a small Copy value, Prng::position) and Self::undo must restore it. A move may consume a variable number of draws, so the pre-move position cannot be recovered by counting draws; it must be snapshotted up front. The clone path gets this for free by cloning the whole state.

Required Associated Types§

Source

type UndoRecord

Enough information to reverse one Self::apply_undoable call.

Required Methods§

Source

fn apply_undoable( &self, state: &mut Self::State, player: PlayerId, action: Self::Action, ) -> Self::UndoRecord

Advances state in place like Game::apply, returning a record that Self::undo can use to reverse it exactly (including the generator position).

Source

fn undo(&self, state: &mut Self::State, record: Self::UndoRecord)

Reverses the move that produced record, restoring state (and its generator position) to what it was before.

Implementors§