1
0
Fork
You've already forked big-brain
0
forked from zkat/big-brain
Utility AI library for the Bevy game engine
  • Rust 99.7%
  • Just 0.3%
2026年04月21日 11:20:31 +08:00
.github migrate bevy@0.18 2026年04月21日 11:20:31 +08:00
assets/models examples: 3d RTS example ( #89 ) 2024年01月09日 15:28:45 -08:00
derive feat(bevy): Update to bevy 0.16 ( #116 ) 2025年04月28日 06:26:37 -07:00
examples migrate bevy@0.18 2026年04月21日 11:20:31 +08:00
src migrate bevy@0.18 2026年04月21日 11:20:31 +08:00
tests feat(deps): Updated to Bevy 0.17 ( #119 ) 2025年10月07日 08:39:37 -07:00
.gitignore chore: dependency of bevy use specified path & add gitignore folder of idea 2026年01月27日 14:27:46 +08:00
Cargo.toml migrate bevy@0.18 2026年04月21日 11:20:31 +08:00
CHANGELOG.md docs: update changelog 2024年11月30日 10:54:29 -08:00
cliff.toml meta: add publishing bits 2021年09月15日 20:52:13 -07:00
justfile docs: document move to codeberg 2025年10月07日 08:40:09 -07:00
LICENSE.md feat(license): change license to Apache-2.0 2021年09月15日 20:52:53 -07:00
README.md migrate bevy@0.18 2026年04月21日 11:20:31 +08:00
README.tpl docs: document move to codeberg 2025年10月07日 08:40:09 -07:00

big-brain

crates.io docs.rs Apache 2.0

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.

Features

  • Highly concurrent/parallelizable evaluation.
  • Integrates smoothly with Bevy.
  • Proven game AI model.
  • Highly composable and reusable.
  • State machine-style continuous actions/behaviors.
  • Action cancellation.

Example

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.

Scorers

Scorers 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.

usebevy::prelude::*;usebig_brain::prelude::*;#[derive(Debug, Clone, Component, ScorerBuilder)]pubstruct Thirsty;pubfn thirsty_scorer_system(thirsts: Query<&Thirst>,mutquery: Query<(&Actor,&mutScore),With<Thirsty>>,){for(Actor(actor),mutscore)inquery.iter_mut(){ifletOk(thirst)=thirsts.get(*actor){score.set(thirst.thirst);}}}
Actions

Actions are the actual things your entities will do. They are connected to ActionStates that represent the current execution state of the state machine.

usebevy::prelude::*;usebig_brain::prelude::*;#[derive(Debug, Clone, Component, ActionBuilder)]pubstruct Drink;fn drink_action_system(mutthirsts: Query<&mutThirst>,mutquery: Query<(&Actor,&mutActionState),With<Drink>>,){for(Actor(actor),mutstate)inquery.iter_mut(){ifletOk(mutthirst)=thirsts.get_mut(*actor){match*state{ActionState::Requested=>{thirst.thirst=10.0;*state=ActionState::Success;}ActionState::Cancelled=>{*state=ActionState::Failure;}_=>{}}}}}
Thinkers

Finally, you can use it when define the Thinker, which you can attach as a regular Component:

fn spawn_entity(cmd: &mutCommands){cmd.spawn((Thirst(70.0,2.0),Thinker::build().picker(FirstToScore{threshold: 0.8}).when(Thirsty,Drink),));}
App

Once all that's done, we just add our systems and off we go!

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)).add_systems(PreUpdate,thirsty_scorer_system.in_set(BigBrainSet::Scorers)).run();}

bevy version and MSRV

The current version of big-brain is compatible with bevy@0.18.0.

The Minimum Supported Rust Version for big-brain should be considered to be the same as bevy's, which as of the time of this writing was "the latest stable release".

Reflection

All relevant big-brain types implement the bevy Reflect trait, so you should be able to get some useful display info while using things like bevy_inspector_egui.

This implementation should not be considered stable, and individual fields made visible may change at any time and not be considered towards semver. Please use this feature only for debugging.

Contributing

  1. Install the latest Rust toolchain (stable supported).
  2. cargo run --example thirst
  3. Happy hacking!

License

This project is licensed under the Apache-2.0 License.