Crates.io | beehave |
lib.rs | beehave |
version | 0.0.4 |
source | src |
created_at | 2015-02-12 08:23:13.040666 |
updated_at | 2016-08-29 07:12:14.484164 |
description | A simple library for defining and evaluating a hierarchical state machine (behaviour tree). |
homepage | https://github.com/Archytaus/beehave |
repository | https://github.com/Archytaus/beehave |
max_upload_size | |
id | 1384 |
size | 31,686 |
A simple library for defining and evaluating a hierarchical state machine (behaviour tree).
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)
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
Beehave was created by Ryan Scott is distributed under the MIT license.