{"id":15017961,"url":"https://github.com/zkat/big-brain","last_synced_at":"2025-05-13T22:08:43.756Z","repository":{"id":39001903,"uuid":"278763279","full_name":"zkat/big-brain","owner":"zkat","description":"Utility AI library for the Bevy game engine","archived":false,"fork":false,"pushed_at":"2025-04-28T13:26:37.000Z","size":596,"stargazers_count":1185,"open_issues_count":17,"forks_count":73,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-29T23:11:59.937Z","etag":null,"topics":["bevy"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zkat.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["zkat"]}},"created_at":"2020-07-11T01:08:31.000Z","updated_at":"2025-04-28T13:26:42.000Z","dependencies_parsed_at":"2023-02-16T04:46:08.715Z","dependency_job_id":"88bafc42-509d-4ddc-ba1d-2c9bb5892219","html_url":"https://github.com/zkat/big-brain","commit_stats":{"total_commits":186,"total_committers":23,"mean_commits":8.08695652173913,"dds":"0.19892473118279574","last_synced_commit":"db1509def03b8513dbd9aed4510ddac67a6fe81e"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fbig-brain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fbig-brain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fbig-brain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fbig-brain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zkat","download_url":"https://codeload.github.com/zkat/big-brain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254036829,"owners_count":22003654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bevy"],"created_at":"2024-09-24T19:51:15.438Z","updated_at":"2025-05-13T22:08:38.729Z","avatar_url":"https://github.com/zkat.png","language":"Rust","funding_links":["https://github.com/sponsors/zkat"],"categories":["Rust","Plugins and Crates"],"sub_categories":["AI"],"readme":"# `big-brain``\n\n[![crates.io](https://img.shields.io/crates/v/big-brain.svg)](https://crates.io/crates/big-brain)\n[![docs.rs](https://docs.rs/big-brain/badge.svg)](https://docs.rs/big-brain)\n[![Apache\n2.0](https://img.shields.io/badge/license-Apache-blue.svg)](./LICENSE.md)\n\n`big-brain` is a [Utility\nAI](https://en.wikipedia.org/wiki/Utility_system) library for games, built\nfor the [Bevy Game Engine](https://bevyengine.org/)\n\nIt lets you define complex, intricate AI behaviors for your entities based\non their perception of the world. Definitions are heavily data-driven,\nusing plain Rust, and you only need to program Scorers (entities that look\nat your game world and come up with a Score), and Actions (entities that\nperform actual behaviors upon the world). No other code is needed for\nactual AI behavior.\n\nSee [the documentation](https://docs.rs/big-brain) for more details.\n\n#### Features\n\n* Highly concurrent/parallelizable evaluation.\n* Integrates smoothly with Bevy.\n* Proven game AI model.\n* Highly composable and reusable.\n* State machine-style continuous actions/behaviors.\n* Action cancellation.\n\n#### Example\n\nAs a developer, you write application-dependent code to define\n[`Scorers`](#scorers) and [`Actions`](#actions), and then put it all\ntogether like building blocks, using [`Thinkers`](#thinkers) that will\ndefine the actual behavior.\n\n##### Scorers\n\n`Scorer`s are entities that look at the world and evaluate into `Score`\nvalues. You can think of them as the \"eyes\" of the AI system. They're a\nhighly-parallel way of being able to look at the `World` and use it to\nmake some decisions later.\n\n```rust\nuse bevy::prelude::*;\nuse big_brain::prelude::*;\n\n#[derive(Debug, Clone, Component, ScorerBuilder)]\npub struct Thirsty;\n\npub fn thirsty_scorer_system(\n    thirsts: Query\u003c\u0026Thirst\u003e,\n    mut query: Query\u003c(\u0026Actor, \u0026mut Score), With\u003cThirsty\u003e\u003e,\n) {\n    for (Actor(actor), mut score) in query.iter_mut() {\n        if let Ok(thirst) = thirsts.get(*actor) {\n            score.set(thirst.thirst);\n        }\n    }\n}\n```\n\n##### Actions\n\n`Action`s are the actual things your entities will _do_. They are\nconnected to `ActionState`s that represent the current execution state of\nthe state machine.\n\n```rust\nuse bevy::prelude::*;\nuse big_brain::prelude::*;\n\n#[derive(Debug, Clone, Component, ActionBuilder)]\npub struct Drink;\n\nfn drink_action_system(\n    mut thirsts: Query\u003c\u0026mut Thirst\u003e,\n    mut query: Query\u003c(\u0026Actor, \u0026mut ActionState), With\u003cDrink\u003e\u003e,\n) {\n    for (Actor(actor), mut state) in query.iter_mut() {\n        if let Ok(mut thirst) = thirsts.get_mut(*actor) {\n            match *state {\n                ActionState::Requested =\u003e {\n                    thirst.thirst = 10.0;\n                    *state = ActionState::Success;\n                }\n                ActionState::Cancelled =\u003e {\n                    *state = ActionState::Failure;\n                }\n                _ =\u003e {}\n            }\n        }\n    }\n}\n```\n\n##### Thinkers\n\nFinally, you can use it when define the `Thinker`, which you can attach as\na regular Component:\n\n```rust\nfn spawn_entity(cmd: \u0026mut Commands) {\n    cmd.spawn((\n        Thirst(70.0, 2.0),\n        Thinker::build()\n            .picker(FirstToScore { threshold: 0.8 })\n            .when(Thirsty, Drink),\n    ));\n}\n```\n\n##### App\n\nOnce all that's done, we just add our systems and off we go!\n\n```rust\nfn main() {\n    App::new()\n        .add_plugins(DefaultPlugins)\n        .add_plugins(BigBrainPlugin::new(PreUpdate))\n        .add_systems(Startup, init_entities)\n        .add_systems(Update, thirst_system)\n        .add_systems(PreUpdate, drink_action_system.in_set(BigBrainSet::Actions))\n        .add_systems(PreUpdate, thirsty_scorer_system.in_set(BigBrainSet::Scorers))\n        .run();\n}\n```\n\n#### bevy version and MSRV\n\nThe current version of `big-brain` is compatible with `bevy` 0.16.0.\n\nThe Minimum Supported Rust Version for `big-brain` should be considered to\nbe the same as `bevy`'s, which as of the time of this writing was \"the\nlatest stable release\".\n\n#### Reflection\n\nAll relevant `big-brain` types implement the bevy `Reflect` trait, so you\nshould be able to get some useful display info while using things like\n[`bevy_inspector_egui`](https://crates.io/crates/bevy_inspector_egui).\n\nThis implementation should **not** be considered stable, and individual\nfields made visible may change at **any time** and not be considered\ntowards semver. Please use this feature **only for debugging**.\n\n#### Contributing\n\n1. Install the latest Rust toolchain (stable supported).\n2. `cargo run --example thirst`\n3. Happy hacking!\n\n#### License\n\nThis project is licensed under [the Apache-2.0 License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkat%2Fbig-brain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzkat%2Fbig-brain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkat%2Fbig-brain/lists"}