Skip to content
Snippets Groups Projects
Unverified Commit 54937950 authored by Kat Marchán's avatar Kat Marchán
Browse files

update readme

parent ad513b36
No related branches found
No related tags found
No related merge requests found
...@@ -3,44 +3,35 @@ library for games, built for the [Bevy Game Engine](https://bevyengine.org/) ...@@ -3,44 +3,35 @@ library for games, built for the [Bevy Game Engine](https://bevyengine.org/)
It lets you define complex, intricate AI behaviors for your entities based on It lets you define complex, intricate AI behaviors for your entities based on
their perception of the world. Definitions are almost entirely data-driven, their perception of the world. Definitions are almost entirely data-driven,
using plain `.ron` files, and you only need to program considerations using plain `.ron` files, and you only need to program Scorers (entities that
(entities that look at your game world), and actions (entities that perform look at your game world), and Actions (entities that perform actual behaviors
actual behaviors upon the world). No other code is needed for actual AI upon the world). No other code is needed for actual AI behavior.
behavior.
See [the documentation](https://docs.rs/big-brain) for more details. See [the documentation](https://docs.rs/big-brain) for more details.
## Example ## Example
First, you define actions and considerations, which are just plain old `specs` First, you define actions and considerations, which are just plain old `Bevy`
`Component`s and `System`s. `Component`s and `System`s.
### Considerations ### Scorers
`Consideration`s are entities that look at the world and evaluate into `Utility` values. `Scorers`s are entities that look at the world and evaluate into `Score` values.
```rust ```rust
use bevy::prelude::*; use bevy::prelude::*;
use big_brain::*; use big_brain::*;
#[derive(Debug, Consideration)] #[derive(Debug, Scorer)]
pub struct ThirstConsideration { pub struct Thirsty;
#[consideration(default)]
pub evaluator: PowerEvaluator,
#[consideration(param)]
pub weight: f32,
}
pub fn thirst_consideration_system( pub fn score_thirst_system(
thirsts: Query<&Thirst>, thirsts: Query<&Thirst>,
mut query: Query<(&Parent, &ThirstConsideration, &mut Utility)>, mut query: Query<(&Parent, &mut Score), With<Thirsty>>,
) { ) {
for (Parent(actor), conser, mut util) in query.iter_mut() { for (Parent(actor), mut score) in query.iter_mut() {
if let Ok(thirst) = thirsts.get(*actor) { if let Ok(thirst) = thirsts.get(*actor) {
*util = Utility { *score = Score(thirst.thirst);
value: conser.evaluator.evaluate(thirst.thirst),
weight: conser.weight,
};
} }
} }
} }
...@@ -51,14 +42,17 @@ pub fn thirst_consideration_system( ...@@ -51,14 +42,17 @@ pub fn thirst_consideration_system(
`Action`s are the actual things your entities will _do_. `Action`s are the actual things your entities will _do_.
```rust ```rust
use bevy::prelude::*;
use big_brain::*;
#[derive(Debug, Action)] #[derive(Debug, Action)]
pub struct DrinkAction {} pub struct Drink;
fn drink_action_system( fn drink_action_system(
mut thirsts: Query<&mut Thirst>, mut thirsts: Query<&mut Thirst>,
mut query: Query<(&Parent, &DrinkAction, &mut ActionState)>, mut query: Query<(&Parent, &mut ActionState), With<Drink>>,
) { ) {
for (Parent(actor), _drink_action, mut state) in query.iter_mut() { for (Parent(actor), mut state) in query.iter_mut() {
if let Ok(mut thirst) = thirsts.get_mut(*actor) { if let Ok(mut thirst) = thirsts.get_mut(*actor) {
match *state { match *state {
ActionState::Requested => { ActionState::Requested => {
...@@ -81,28 +75,28 @@ fn drink_action_system( ...@@ -81,28 +75,28 @@ fn drink_action_system(
Finally, you can use it when define the `Thinker`: Finally, you can use it when define the `Thinker`:
```ron ```ron
// behavior.ron
( (
picker: {"FirstToScore": (threshold: 80.0)}, picker: {"FirstToScore": (threshold: 80.0)},
otherwise: Some({"Meander": ()}),
choices: [( choices: [(
consider: [{"Bladder": (weight: 3.0)}], when: {"Bladder": ()},
// Thinkers are infinitely nestable! They're actually Actions themselves.
then: {"Thinker": ( then: {"Thinker": (
picker: {"FirstToScore": (threshold: 80.0)}, picker: {"FirstToScore": (threshold: 80.0)},
choices: [( choices: [(
consider: [{"Bladder": (weight: 3.0)}], when: [{"Bladder": ()}],
then: {"Pee": ()} then: {"Pee": ()}
)] )]
)} )}
), ( ), (
consider: [{"Thirst": (weight: 2.0)}], // Here you go!
when: {"Thirsty": ()},
then: {"Drink": ()}, then: {"Drink": ()},
), ( ), (
consider: [{"Hunger": (weight: 2.0)}], when: {"Hungry": ()},
then: {"Eat": ()}, then: {"Eat": ()},
)], )],
otherwise: Some({"Meander": ()}),
) )
``` ```
## License ## License
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment