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<'a>(&self, choices: &'a [Choice], scores: &Query<&Score>) -> Option<&'a Choice>;
/**
Picker that chooses the first `Choice` with a [`Score`] higher than its configured `threshold`.
### Example
```no_run
Thinker::build()
.picker(FirstToScore::new(.8))
pub struct FirstToScore {
pub threshold: f32,
}
impl FirstToScore {
pub fn new(threshold: f32) -> Self {
Self { threshold }
}
}
fn pick<'a>(&self, choices: &'a [Choice], scores: &Query<&Score>) -> Option<&'a Choice> {
let value = choice.calculate(scores);