Direction PacManAI::optimalDirection(const std::array & moves) { double closestDistance = std::numeric_limits::infinity(); Direction dir = Direction::NONE; for (const auto & move : moves) { if (move.distanceToTarget < closestDistance) { closestDistance = move.distanceToTarget; dir = move.direction; } } return dir; }