Crate lifers

source ·
Expand description

lifers is an advanced cellular automata creation framework.

It consists of the following parts:

  • Engine: Logic and algorithms behing the automata;
  • API: An interface for creating and interacting with created automata;
  • Frontend(-s): External interfaces that allow to represent simulation data in a different way (graphical, ASCII, etc.).

§Examples

This is how one can implement Conway’s Game of Life with lifers:

// Use a 100x100 grid
use lifers::prelude::*;
use rand::random;

let mut game = Automaton::build((100, 100))
    // Initialize all cells with random states (alive or dead)
    .init(|_| random::<bool>())
    // Count neighbors in radius of 1 for each cell
    .map(|(x, y), _, cells| count_neighbors(cells, (x, y), 1, |b| *b))
    // Change cells' state depending on the number of neighbors
    .run(|_, is_alive, neighbors_n| match is_alive {
        true => (2..=3).contains(neighbors_n),
        false => *neighbors_n == 3,
    });

// Compute the next generation
game.step();

Modules§

  • Automata engine components
  • Frontend specification and helper traits and functions
  • Helper module with all common imports

Macros§

  • Takes an iterator over a Grid<T>. Maps the given function (f: fn((usize, usize), T) -> L) on each cell in the grid. Expands to a nested iterator over f’s return type.