big-brain
big-brain
is a Utility
AI library for games, built
for the Bevy Game Engine
It lets you define complex, intricate AI behaviors for your entities based on their perception of the world. Definitions are heavily data-driven, using plain Rust, and you only need to program Scorers (entities that look at your game world and come up with a Score), and Actions (entities that perform actual behaviors upon the world). No other code is needed for actual AI behavior.
See the documentation for more details.
As a developer, you write application-dependent code to define
Scorers
and Actions
, and then put it all
together like building blocks, using Thinkers
that will
define the actual behavior.
Scorer
s are entities that look at the world and evaluate into Score
values. You can think of them as the "eyes" of the AI system. They're a
highly-parallel way of being able to look at the World
and use it to
make some decisions later.
```rust use bevy::prelude::; use big_brain::prelude::;
pub struct Thirsty;
pub fn thirstyscorersystem(
thirsts: Query<&Thirst>,
mut query: Query<(&Actor, &mut Score), With
Action
s are the actual things your entities will do. They are
connected to ActionState
s that represent the current execution state of
the state machine.
```rust use bevy::prelude::; use big_brain::prelude::;
pub struct Drink;
fn drinkactionsystem(
mut thirsts: Query<&mut Thirst>,
mut query: Query<(&Actor, &mut ActionState), With
Finally, you can use it when define the Thinker
, which you can attach as
a regular Component:
rust
fn spawn_entity(cmd: &mut Commands) {
cmd.spawn((
Thirst(70.0, 2.0),
Thinker::build()
.picker(FirstToScore { threshold: 0.8 })
.when(Thirsty, Drink),
));
}
Once all that's done, we just add our systems and off we go!
rust
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(BigBrainPlugin::new(PreUpdate))
.add_systems(Startup, init_entities)
.add_systems(Update, thirst_system)
.add_systems(PreUpdate, (
drink_action_system.in_set(BigBrainSet::Actions),
thirsty_scorer_system.in_set(BigBrainSet::Scorers),
))
.run();
}
The current version of big-brain
is compatible with bevy
0.11.0.
cargo run --example thirst
This project is licensed under the Apache-2.0 License.