added test, idle afte goal reached

This commit is contained in:
2024-01-03 10:57:41 -07:00
parent d69b24dfd8
commit 2e0dbc958b
2 changed files with 41 additions and 2 deletions
+9 -2
View File
@@ -24,7 +24,14 @@ impl AI for Ant {
fn plan(&mut self, w: &World) {
if self.plan.len() == 0 {
self.plan = match self.goal {
AIGoal::Reach(target) => astar(&self.pos, &target),
AIGoal::Reach(target) => {
if &self.pos == &target {
self.goal = AIGoal::Idle;
vec![]
} else {
astar(&self.pos, &target)
}
},
AIGoal::Idle => vec![],
}
}
@@ -54,6 +61,7 @@ impl AI for Ant {
} else {
w.clear(pos);
match self.goal {
// push plan back because we haven't actually moved towards it
AIGoal::Reach(_) => {
self.plan.push(pos);
}
@@ -62,7 +70,6 @@ impl AI for Ant {
}
}
// need to check if progress has been made towards the plan
BoardCommand::Noop
}
}