Skip to content
Snippets Groups Projects
pickers.rs 758 B
Newer Older
use bevy::prelude::*;

Kat Marchán's avatar
Kat Marchán committed
use serde::{Deserialize, Serialize};

use crate::{choices::Choice, scorers::Score, thinker::ActionEnt};
Kat Marchán's avatar
Kat Marchán committed

#[typetag::serde]
pub trait Picker: std::fmt::Debug + Sync + Send {
    fn pick(&self, _choices: &[Choice], _utilities: &Query<&Score>) -> Option<ActionEnt>;
Kat Marchán's avatar
Kat Marchán committed
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct FirstToScore {
    pub threshold: f32,
}

#[typetag::serde]
impl Picker for FirstToScore {
    fn pick(&self, choices: &[Choice], utilities: &Query<&Score>) -> Option<ActionEnt> {
Kat Marchán's avatar
Kat Marchán committed
        for choice in choices {
            let value = choice.calculate(utilities);
            if value >= self.threshold {
                return Some(choice.action_state);