Create pellet_closest_to_pacman_simple
This commit is contained in:
parent
c981f127ed
commit
18f05f0ef4
1 changed files with 15 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
|||
GridPosition PacManAI::pelletClosestToPacman(GridPosition pacmanGridPosition,
|
||||
std::vector<GridPosition> & pellets) {
|
||||
GridPosition closestPellet = { 0, 0 };
|
||||
double closestDistance = std::numeric_limits<double>::infinity();
|
||||
|
||||
for (const auto & pellet : pellets) {
|
||||
const double distance = positionDistance(pacmanGridPosition, pellet);
|
||||
if (distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closestPellet = pellet;
|
||||
}
|
||||
}
|
||||
|
||||
return closestPellet;
|
||||
}
|
Loading…
Reference in a new issue