From 07b60ed895ed75a80a2908d815ff8ca15c99e63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= <kzm@zkat.tech> Date: Sun, 25 Apr 2021 22:12:30 -0700 Subject: [PATCH] docs: updated docs and examples --- README.md | 10 +++++----- examples/thirst.rs | 16 ++++++---------- src/evaluators.rs | 2 +- src/lib.rs | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 913b889..5b54ac4 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,9 @@ define the actual behavior. #### Scorers -`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. +`Scorer`s are entities that look at the world and evaluate into [`Score`](scorers::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. -They are created by types that implement `ScorerBuilder`. +They are created by types that implement [`ScorerBuilder`](scorers::ScorerBuilder). ```rust use bevy::prelude::*; @@ -75,7 +75,7 @@ pub fn thirsty_scorer_system( #### Actions -`Action`s are the actual things your entities will _do_. They are connected to `ActionState`s, and are created by types implementing `ActionBuilder`. +`Action`s are the actual things your entities will _do_. They are connected to [`ActionState`](actions::ActionState)s, and are created by types implementing [`ActionBuilder`](actions::ActionBuilder). ```rust use bevy::prelude::*; @@ -122,13 +122,13 @@ fn drink_action_system( #### Thinkers -Finally, you can use it when define the `Thinker`, which you can attach as a +Finally, you can use it when define the [`Thinker`](thinker::Thinker), which you can attach as a regular Component: ```rust cmd.spawn().insert(Thirst::new(70.0, 2.0)).insert( Thinker::build() - .picker(FirstToScore { threshold: 80.0 }) + .picker(FirstToScore { threshold: 0.8 }) .when(Thirsty::build(), Drink::build()), ); ``` diff --git a/examples/thirst.rs b/examples/thirst.rs index 30c378e..50b125a 100644 --- a/examples/thirst.rs +++ b/examples/thirst.rs @@ -20,10 +20,11 @@ impl Thirst { pub fn thirst_system(time: Res<Time>, mut thirsts: Query<&mut Thirst>) { for mut thirst in thirsts.iter_mut() { - thirst.thirst += thirst.per_second * (time.delta().as_micros() as f32 / 1000000.0); + thirst.thirst += thirst.per_second * (time.delta().as_micros() as f32 / 1_000_000.0); if thirst.thirst >= 100.0 { thirst.thirst = 100.0; } + println!("Thirst: {}", thirst.thirst); } } @@ -120,16 +121,12 @@ fn idle_system(mut query: Query<&mut ActionState, With<Idle>>) { for mut state in query.iter_mut() { match *state { ActionState::Requested => { - println!("Idling..."); *state = ActionState::Executing; } ActionState::Cancelled => { - println!("Idling cancelled"); *state = ActionState::Success; } - ActionState::Executing => { - println!("Idled"); - } + ActionState::Executing => {} _ => {} } } @@ -174,9 +171,8 @@ pub fn thirsty_scorer_system( // generally "the higher the better", and "first across the finish // line", but that's all configurable using Pickers! // - // The score here must be between 0.0 and 100.0. - score.set(thirst.thirst); - println!("Thirst: {}", thirst.thirst); + // The score here must be between 0.0 and 1.0. + score.set(thirst.thirst / 100.); } } } @@ -190,7 +186,7 @@ pub fn init_entities(mut cmd: Commands) { // Thinker::build().component() will return a regular component you // can attach normally! Thinker::build() - .picker(FirstToScore { threshold: 80.0 }) + .picker(FirstToScore { threshold: 0.8 }) // Note that what we pass in are _builders_, not components! .when(Thirsty::build(), Drink::build()) .otherwise(Idle::build()), diff --git a/src/evaluators.rs b/src/evaluators.rs index e46b78f..c4b4ade 100644 --- a/src/evaluators.rs +++ b/src/evaluators.rs @@ -1,5 +1,5 @@ /*! -Utilities for turning values of 0.0..=100.0 into different curves. +Utilities for turning values within a certain range into different curves. */ /** diff --git a/src/lib.rs b/src/lib.rs index 17e7c3f..b2e459c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,7 +127,7 @@ regular Component: ```no_run cmd.spawn().insert(Thirst::new(70.0, 2.0)).insert( Thinker::build() - .picker(FirstToScore { threshold: 80.0 }) + .picker(FirstToScore { threshold: 0.8 }) .when(Thirsty::build(), Drink::build()), ); ``` -- GitLab