Trait djinn::Simulation [] [src]

pub trait Simulation: Sized + Send + Sync + Clone {
    type State: State;
    type World: State;
    type Update: Update;
    fn decide<R: Redis>(
        &self,
        agent: &Agent<Self::State>,
        world: &Self::World,
        population: &Population<Self, R>,
        updates: &mut Updates<Self>
    ); fn update(
        &self,
        state: &mut Self::State,
        updates: Vec<Self::Update>
    ) -> bool; fn on_spawns<R: Redis>(
        &self,
        agents: Vec<Agent<Self::State>>,
        population: &Population<Self, R>
    ) { ... } fn on_deaths<R: Redis>(
        &self,
        agents: Vec<Agent<Self::State>>,
        population: &Population<Self, R>
    ) { ... } fn world_decide<R: Redis>(
        &self,
        world: &Self::World,
        population: &Population<Self, R>,
        updates: &mut Updates<Self>
    ) { ... } fn world_update(
        &self,
        world: Self::World,
        updates: Vec<Self::Update>
    ) -> Self::World { ... } }

This trait's implementation defines the main logic of a simulation.

A single simulation step consists of two synchronized phases:

  1. decide: this is a read-only phase where agents decide on what updates to apply. The updates themselves are not applied in this phase.
  2. update: this is a phase where agents consider queued updates and compute a new state accordingly.

Associated Types

Required Methods

Computes updates for the specified agents and/or other agents.

Compute a final updated state given a starting state and updates.

If there is some update you want to do every step, things will run faster if you implement it here directly rather than using an Update.

Provided Methods

Called whenever a new agent is spawned. You can use this to, for example, build an index of agents by state values.

Called whenever an agent is killed. You can use this to, for example, remove an agent from an index.

Compute updates for the world.

Compute a final state for the world given updates.

Implementors