Skip to content
Snippets Groups Projects
Unverified Commit 71f5122e authored by Kat Marchán's avatar Kat Marchán
Browse files

feat(score): scores are now 0.0..=1.0, not 0.0..=100.0

BREAKING CHANGE: Please adjust your scorers to only work with 0.0 to 1.0 values
parent 2d54e51f
No related branches found
No related tags found
No related merge requests found
......@@ -22,10 +22,10 @@ pub struct LinearEvaluator {
impl LinearEvaluator {
pub fn new() -> Self {
Self::new_full(0.0, 0.0, 100.0, 100.0)
Self::new_full(0.0, 0.0, 1.0, 1.0)
}
pub fn new_ranged(min: f32, max: f32) -> Self {
Self::new_full(min, 0.0, max, 100.0)
Self::new_full(min, 0.0, max, 1.0)
}
fn new_full(xa: f32, ya: f32, xb: f32, yb: f32) -> Self {
Self {
......@@ -67,10 +67,10 @@ pub struct PowerEvaluator {
impl PowerEvaluator {
pub fn new(power: f32) -> Self {
Self::new_full(power, 0.0, 0.0, 100.0, 100.0)
Self::new_full(power, 0.0, 0.0, 1.0, 1.0)
}
pub fn new_ranged(power: f32, min: f32, max: f32) -> Self {
Self::new_full(power, min, 0.0, max, 100.0)
Self::new_full(power, min, 0.0, max, 1.0)
}
fn new_full(power: f32, xa: f32, ya: f32, xb: f32, yb: f32) -> Self {
Self {
......@@ -115,11 +115,11 @@ pub struct SigmoidEvaluator {
impl SigmoidEvaluator {
pub fn new(k: f32) -> Self {
Self::new_full(k, 0.0, 0.0, 100.0, 100.0)
Self::new_full(k, 0.0, 0.0, 1.0, 1.0)
}
pub fn new_ranged(k: f32, min: f32, max: f32) -> Self {
Self::new_full(k, min, 0.0, max, 100.0)
Self::new_full(k, min, 0.0, max, 1.0)
}
fn new_full(k: f32, xa: f32, ya: f32, xb: f32, yb: f32) -> Self {
......
......@@ -22,7 +22,7 @@ Picker that chooses the first `Choice` with a [`Score`] higher than its configur
```no_run
Thinker::build()
.picker(FirstToScore::new(80.))
.picker(FirstToScore::new(.8))
// .when(...)
```
*/
......
/*!
Scorers look at the world and boil down arbitrary characteristics into a range of 0.0..=100.0. This module includes the ScorerBuilder trait and some built-in Composite Scorers.
Scorers look at the world and boil down arbitrary characteristics into a range of 0.0..=1.0. This module includes the ScorerBuilder trait and some built-in Composite Scorers.
*/
use std::sync::Arc;
......@@ -9,7 +9,7 @@ use bevy::prelude::*;
use crate::thinker::{Actor, ScorerEnt};
/**
Score value between `0.0..=100.0` associated with a Scorer.
Score value between `0.0..=1.0` associated with a Scorer.
*/
#[derive(Debug, Clone, Default)]
pub struct Score(pub(crate) f32);
......@@ -26,11 +26,11 @@ impl Score {
### Panics
Panics if `value` isn't within `0.0..=100.0`.
Panics if `value` isn't within `0.0..=1.0`.
*/
pub fn set(&mut self, value: f32) {
if !(0.0..=100.0).contains(&value) {
panic!("Score value must be between 0.0 and 100.0");
if !(0.0..=1.0).contains(&value) {
panic!("Score value must be between 0.0 and 1.0");
}
self.0 = value;
}
......@@ -150,7 +150,7 @@ pub fn all_or_nothing_system(query: Query<(Entity, &AllOrNothing)>, mut scores:
}
}
let mut score = scores.get_mut(aon_ent).expect("where did it go?");
score.set(crate::evaluators::clamp(sum, 0.0, 100.0));
score.set(crate::evaluators::clamp(sum, 0.0, 1.0));
}
}
#[derive(Debug, Clone)]
......@@ -234,7 +234,7 @@ pub fn sum_of_scorers_system(query: Query<(Entity, &SumOfScorers)>, mut scores:
sum = 0.0;
}
let mut score = scores.get_mut(sos_ent).expect("where did it go?");
score.set(crate::evaluators::clamp(sum, 0.0, 100.0));
score.set(crate::evaluators::clamp(sum, 0.0, 1.0));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment