#fsm #ai #state #game #behaviour

nightly beehave

A simple library for defining and evaluating a hierarchical state machine (behaviour tree)

4 releases

Uses old Rust 2015

0.0.4 Aug 29, 2016
0.0.3 Dec 20, 2015
0.0.2 Feb 15, 2015
0.0.1 Feb 12, 2015

#19 in #fsm

Download history 1/week @ 2023-11-05 2/week @ 2023-11-12 1/week @ 2023-11-19 15/week @ 2023-11-26 9/week @ 2023-12-03 1/week @ 2023-12-10 5/week @ 2023-12-17 14/week @ 2023-12-24 1/week @ 2023-12-31 1/week @ 2024-01-07 5/week @ 2024-01-21 17/week @ 2024-01-28 2/week @ 2024-02-04 16/week @ 2024-02-11 102/week @ 2024-02-18

137 downloads per month

MIT license

14KB
268 lines

Beehave Build Status

A simple library for defining and evaluating a hierarchical state machine (behaviour tree).

Documentation

Compatibility

Because this library uses fn_traits and unboxed_closures it will only compile using rust nightly. See rust-lang/rust#29625 for the related issue around stabilization.

This was last tested against rustc 1.13.0-nightly (a23064af5 2016-08-27)

Example

Building a behaviour tree using the supplied macros:

let world_behaviour: Selector<World> = behaviour_selector!("World Root", [
    condition!("Ensure Can Shine",
        |world: &mut World| {
            world.can_shine()
        },
        action!("Cycle Day/Night", |world: &mut World| {
            world.toggle_sun()
        })
    ),
    condition!("Ensure Can Rain",
        |world: &mut World| {
            world.can_rain()
        },
        action!("Rain", |world: &mut World| {
            world.rain()
        })
    )
]);

let tree_behaviour: Selector<Tree> = behaviour_selector!("Tree Root", [
    behaviour_sequence!("Photosynthesise", [
        condition!("Ensure Can Make Energy",
            |tree: &mut Tree| {
                tree.can_make_energy()
            },
            action!("Make Energy", |tree: &mut Tree| {
                tree.make_energy()
            })
        ),
        condition!("Ensure Can Grow",
            |tree: &mut Tree| {
                tree.can_grow()
            },
            action!("Grow", |tree: &mut Tree| {
                tree.grow()
            })
        ),
        condition!("Ensure Can Emit Oxygen",
            |tree: &mut Tree| {
                tree.can_emit_oxygen()
            },
            action!("Emit Oxygen", |tree: &mut Tree| {
                tree.emit_oxygen()
            })
        )
    ]),
    condition!("Ensure Can Gather Sun",
        |tree: &mut Tree| {
            tree.can_gather_sun()
        },
        action!("Emit Oxygen", |tree: &mut Tree| {
            tree.gather_sun()
        })
    ),
    condition!("Ensure Can Gather Water",
        |tree: &mut Tree| {
            tree.can_gather_water()
        },
        action!("Emit Oxygen", |tree: &mut Tree| {
            tree.gather_water()
        })
    )
]);

Evaluating the behaviour tree against an actor:

tree_behaviour.evaluate(&mut tree);
world_behaviour.evaluate(&mut world);

For more information please see the full example.

You can run the example using:

cargo run --example main

Design Goals

  • Easily generate an immutable behaviour tree
  • Evaluate the behaviour tree on a mutable actor

See also

PistonDevelopers/ai_behavior

License

Beehave was created by Ryan Scott is distributed under the MIT license.

No runtime deps