emergent
emergent copied to clipboard
Add `From`/`Into` impls to reduce nesting
Right now my reasoner creation looks like:
let reasoner = ReasonerBuilder::default()
.state(State::Idle, ReasonerState::new(0.001, Idle))
.state(
State::Investigate,
ReasonerState::new(
ConditionConsideration::unit(ClosureCondition::new(|p: &Perception| {
p.heard_kill.is_some() || p.player_coords.is_some()
})),
Investigate,
),
)
.state(
State::Attack,
ReasonerState::new(
ConditionConsideration::unit(ClosureCondition::new(|p: &Perception| {
p.sees_player
})),
Attack,
),
)
.state(
State::Dodge,
ReasonerState::new(
ConditionConsideration::unit(ClosureCondition::new(|p: &Perception| {
p.sees_player && p.in_gunsight
})),
Dodge,
),
)
.build();
I think it would make sense to have a few conversions, so something like this might work:
let reasoner = ReasonerBuilder::default()
.state(State::Idle, ReasonerState::new(0.001, Idle))
.state(
State::Investigate,
ReasonerState::new((|p: &Perception| p.heard_kill.is_some()).into(), Investigate)
Where |v: &M| -> bool can convert directly to a consideration. Might make sense to do something similar for ClosureConsideration as well.
Yes, ideally these would be separate traits/functions, but for now it's simplest to locate this with the reasoner creation.
Thanks.