Trait rlifesrc_lib::rules::Rule

source ·
pub trait Rule: Sealed {
    type Desc: Copy;
    type IsGen: Bool;

    // Required methods
    fn has_b0(&self) -> bool;
    fn has_b0_s8(&self) -> bool;
    fn gen(&self) -> usize;
    fn symmetry(&self) -> Symmetry;
    fn new_desc(state: State, succ_state: State) -> Self::Desc;
    fn update_desc(cell: &LifeCell<Self>, state: State, new: bool);
    fn consistify<A: Algorithm<Self>>(
        world: &mut World<Self, A>,
        cell: CellRef<Self>
    ) -> Result<(), A::ConflReason>;
}
Expand description

A cellular automaton rule.

The following rules are supported:

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

Required Associated Types§

source

type Desc: Copy

The type of neighborhood descriptor of the rule.

It describes the states of the successor and neighbors of a cell, and is used to determine the state of the cell in the next generation.

source

type IsGen: Bool

Whether the rule is a Generations rule.

Required Methods§

source

fn has_b0(&self) -> bool

Whether the rule contains B0.

In other words, whether a dead cell would become ALIVE in the next generation, if all its neighbors in this generation are dead.

source

fn has_b0_s8(&self) -> bool

Whether the rule contains both B0 and S8.

In a rule that contains B0, a dead cell would become ALIVE in the next generation, if all its neighbors in this generation are dead.

In a rule that contains S8, a living cell would stay ALIVE in the next generation, if all its neighbors in this generation are alive.

source

fn gen(&self) -> usize

The number of states.

source

fn symmetry(&self) -> Symmetry

The symmetry of the rule.

source

fn new_desc(state: State, succ_state: State) -> Self::Desc

Generates a neighborhood descriptor which says that all neighboring cells have states state, and the successor has state succ_state.

source

fn update_desc(cell: &LifeCell<Self>, state: State, new: bool)

Updates the neighborhood descriptors of all neighbors and the predecessor when the state of one cell is changed.

The state is the new state of the cell when new is true, the old state when new is false.

source

fn consistify<A: Algorithm<Self>>( world: &mut World<Self, A>, cell: CellRef<Self> ) -> Result<(), A::ConflReason>

Consistifies a cell.

Examines the state and the neighborhood descriptor of the cell, and makes sure that it can validly produce the cell in the next generation. If possible, determines the states of some of the cells involved.

Returns false if there is a conflict, true if the cells are consistent.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Rule for Life

source§

impl Rule for LifeGen

NOTE: This implementation does work when the number of states is 2.

source§

impl Rule for NtLife

source§

impl Rule for NtLifeGen

NOTE: This implementation does work when the number of states is 2.