1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use bevy::prelude::*;
use crate::{choices::Choice, scorers::Score};
pub trait Picker: std::fmt::Debug + Sync + Send {
fn pick(&self, _choices: &[Choice], _utilities: &Query<&Score>) -> Option<Choice>;
}
#[derive(Debug, Clone, Default)]
pub struct FirstToScore {
pub threshold: f32,
}
impl FirstToScore {
pub fn new(threshold: f32) -> Self {
Self { threshold }
}
}
impl Picker for FirstToScore {
fn pick(&self, choices: &[Choice], scores: &Query<&Score>) -> Option<Choice> {
for choice in choices {
let value = choice.calculate(scores);
if value >= self.threshold {
return Some(choice.clone());
}
}
None
}
}