Skip to content

Latest commit

History

33 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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:&mutWorld| {
world.can_shine()},
action!("Cycle Day/Night", |world:&mutWorld| {
world.toggle_sun()})),
condition!("Ensure Can Rain",
|world:&mutWorld| {
world.can_rain()},
action!("Rain", |world:&mutWorld| {
world.rain()}))]);let tree_behaviour:Selector<Tree> = behaviour_selector!("Tree Root",[
behaviour_sequence!("Photosynthesise",[
condition!("Ensure Can Make Energy",
|tree:&mutTree| {
tree.can_make_energy()},
action!("Make Energy", |tree:&mutTree| {
tree.make_energy()})),
condition!("Ensure Can Grow",
|tree:&mutTree| {
tree.can_grow()},
action!("Grow", |tree:&mutTree| {
tree.grow()})),
condition!("Ensure Can Emit Oxygen",
|tree:&mutTree| {
tree.can_emit_oxygen()},
action!("Emit Oxygen", |tree:&mutTree| {
tree.emit_oxygen()}))]),
condition!("Ensure Can Gather Sun",
|tree:&mutTree| {
tree.can_gather_sun()},
action!("Emit Oxygen", |tree:&mutTree| {
tree.gather_sun()})),
condition!("Ensure Can Gather Water",
|tree:&mutTree| {
tree.can_gather_water()},
action!("Emit Oxygen", |tree:&mutTree| {
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.

About

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

Resources

Stars

15 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages