Trait Behavior

Source
pub trait Behavior<D: Domain>: 'static {
    // Required methods
    fn is_valid(
        &self,
        tick: u64,
        state: StateDiffRef<'_, D>,
        agent: AgentId,
    ) -> bool;
    fn add_own_tasks(
        &self,
        tick: u64,
        state: StateDiffRef<'_, D>,
        agent: AgentId,
        tasks: &mut Vec<Box<dyn Task<D>>>,
    );

    // Provided methods
    fn get_dependent_behaviors(&self) -> &'static [&'static dyn Behavior<D>] { ... }
    fn add_tasks(
        &self,
        tick: u64,
        state: StateDiffRef<'_, D>,
        agent: AgentId,
        tasks: &mut Vec<Box<dyn Task<D>>>,
    ) { ... }
}
Expand description

A possibly-recursive set of possible tasks.

You need to implement at least two methods: is_valid and add_own_tasks.

Required Methods§

Source

fn is_valid( &self, tick: u64, state: StateDiffRef<'_, D>, agent: AgentId, ) -> bool

Returns if the behavior is valid for the given agent in the given world state.

Source

fn add_own_tasks( &self, tick: u64, state: StateDiffRef<'_, D>, agent: AgentId, tasks: &mut Vec<Box<dyn Task<D>>>, )

Collects valid tasks for the given agent in the given world state.

Provided Methods§

Source

fn get_dependent_behaviors(&self) -> &'static [&'static dyn Behavior<D>]

Returns dependent behaviors.

Source

fn add_tasks( &self, tick: u64, state: StateDiffRef<'_, D>, agent: AgentId, tasks: &mut Vec<Box<dyn Task<D>>>, )

Helper method to recursively collect all valid tasks for the given agent in the given world state.

It will not do anything if the behavior is invalid at that point.

Implementors§