Newer
Older
/*!
Pickers are used by Thinkers to determine which of its Scorers will "win".
*/
use crate::{choices::Choice, scorers::Score};
/**
Required trait for Pickers. A Picker is given a slice of choices and a query that can be passed into `Choice::calculate`.
Implementations of `pick` must return `Some(Choice)` for the `Choice` that was picked, or `None`.
*/
fn pick(&self, _choices: &[Choice], _utilities: &Query<&Score>) -> Option<Choice>;
/**
Picker that chooses the first `Choice` with a [`Score`] higher than its configured `threshold`.
### Example
```no_run
Thinker::build()
.picker(FirstToScore::new(80.))
// .when(...)
```
*/
pub struct FirstToScore {
pub threshold: f32,
}
impl FirstToScore {
pub fn new(threshold: f32) -> Self {
Self { threshold }
}
}
fn pick(&self, choices: &[Choice], scores: &Query<&Score>) -> Option<Choice> {
let value = choice.calculate(scores);