Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
big-brain
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Louis
big-brain
Commits
54937950
Unverified
Commit
54937950
authored
4 years ago
by
Kat Marchán
Browse files
Options
Downloads
Patches
Plain Diff
update readme
parent
ad513b36
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+25
-31
25 additions, 31 deletions
README.md
with
25 additions
and
31 deletions
README.md
+
25
−
31
View file @
54937950
...
@@ -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.
###
Consideration
s
###
Scorer
s
`
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
Utili
ty
)
>
,
mut
query
:
Query
<
(
&
Parent
,
&
mut
Score
),
With
<
Thirs
ty
>
>
,
)
{
)
{
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
Drink
Action
{}
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
:
[
{"Hung
e
r": (
weight: 2.0
)}
]
,
when
: {"Hungr
y
": ()},
then: {"Eat": ()},
then: {"Eat": ()},
)],
)],
otherwise: Some({"Meander": ()}),
)
)
```
```
## License
## License
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment