Newer
Older
use serde::Deserialize;
use crate::{
actions::{Action, ActionState},
};
// Contains different types of Considerations and Actions
#[derive(Debug)]
pub struct Choice {
pub measure: Box<dyn Measure>,
pub fn calculate(&self, utilities: &Query<&Score>) -> f32 {
self.measure.calculate(
self.utilities
.iter()
.map(|choice_cons| {
utilities
.expect("Where did the utility go?")
})
.collect(),
)
}
}
#[derive(Debug, Deserialize)]
pub struct ChoiceBuilder {
pub then: Box<dyn Action>,
}
impl ChoiceBuilder {
pub fn build(self, actor: Entity, cmd: &mut Commands) -> Choice {
let action = self.then;
Choice {
measure: Box::new(WeightedMeasure),
utilities: self
.consider
.iter()
action_state: ActionState::build(action, actor, cmd),