pub trait Algorithm<R: Rule>: Sealed {
    type Reason: Reason<R>;
    type ConflReason;

    // Required methods
    fn new() -> Self;
    fn confl_from_cell(cell: CellRef<R>) -> Self::ConflReason;
    fn confl_from_sym(cell: CellRef<R>, sym: CellRef<R>) -> Self::ConflReason;
    fn init_front(world: World<R, Self>) -> World<R, Self>;
    fn set_cell(
        world: &mut World<R, Self>,
        cell: CellRef<R>,
        state: State,
        reason: Self::Reason
    ) -> Result<(), Self::ConflReason>;
    fn go(world: &mut World<R, Self>, step: &mut u64) -> bool;
    fn retreat(world: &mut World<R, Self>) -> bool;
    fn deser_reason(
        world: &World<R, Self>,
        ser: &ReasonSer
    ) -> Result<Self::Reason, Error>;
}
Expand description

The search algorithms.

Currently only two algorithms are supported:

  • LifeSrc: The default algorithm based on David Bell’s lifesrc.
  • Backjump: (Experimental) Adding Backjumping to the original lifesrc algorithm. Very slow. Do not use it.

This trait is sealed and cannot be implemented outside of this crate.

Required Associated Types§

source

type Reason: Reason<R>

Reasons for setting a cell.

source

type ConflReason

Reasons for a conflict. Ignored in LifeSrc algorithm.

Required Methods§

source

fn new() -> Self

Generate new algorithm data.

source

fn confl_from_cell(cell: CellRef<R>) -> Self::ConflReason

Conflict when constitifying a cell.

source

fn confl_from_sym(cell: CellRef<R>, sym: CellRef<R>) -> Self::ConflReason

Conflict from symmetry.

source

fn init_front(world: World<R, Self>) -> World<R, Self>

Conflict when constitifying a cell.

source

fn set_cell( world: &mut World<R, Self>, cell: CellRef<R>, state: State, reason: Self::Reason ) -> Result<(), Self::ConflReason>

Sets the state of a cell, push it to the set_stack, and update the neighborhood descriptor of its neighbors.

The original state of the cell must be unknown.

source

fn go(world: &mut World<R, Self>, step: &mut u64) -> bool

Keeps proceeding and backtracking, until there are no more cells to examine (and returns true), or the backtracking goes back to the time before the first cell is set (and returns false).

It also records the number of steps it has walked in the parameter step.

source

fn retreat(world: &mut World<R, Self>) -> bool

Retreats to the last time when a unknown cell is decided by choice, and switch that cell to the other state.

Returns true if successes, false if it goes back to the time before the first cell is set.

source

fn deser_reason( world: &World<R, Self>, ser: &ReasonSer ) -> Result<Self::Reason, Error>

Available on crate feature serde only.

Restore the reason from a ReasonSer.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<R: Rule> Algorithm<R> for LifeSrc

source§

impl<R: Rule<IsGen = False>> Algorithm<R> for Backjump<R>