Ex 25: Implement pelletClosestToPacman().
This commit is contained in:
parent
4302a86d7a
commit
a8804d096b
2 changed files with 8 additions and 4 deletions
|
@ -16,10 +16,13 @@ Direction PacManAI::suggestedDirection() const {
|
|||
|
||||
// This function is not yet implemented.
|
||||
// You will implement it as part of module 25.
|
||||
GridPosition PacManAI::pelletClosestToPacman(GridPosition,
|
||||
std::vector<GridPosition> &) {
|
||||
|
||||
GridPosition PacManAI::pelletClosestToPacman(GridPosition position,
|
||||
std::vector<GridPosition> & pellets) {
|
||||
if (pellets.empty())
|
||||
return { 0, 0 };
|
||||
return *std::min_element(pellets.begin(), pellets.end(), [position](GridPosition a, GridPosition b) {
|
||||
return positionDistance(a, position) < positionDistance(b, position);
|
||||
});
|
||||
}
|
||||
|
||||
// This function is not yet implemented.
|
||||
|
|
|
@ -7,6 +7,7 @@ TEST_CASE("Find pellet closest to PacMan", "[AI]") {
|
|||
PacManAI AI;
|
||||
using TestData = std::tuple<GridPosition, std::vector<GridPosition>, GridPosition>;
|
||||
auto data = GENERATE(
|
||||
TestData{{5, 5}, {}, {0, 0}},
|
||||
TestData{{5, 5}, {{5, 6}}, {5, 6}},
|
||||
TestData{{5, 5}, {{5, 5}}, {5, 5}},
|
||||
TestData{{5, 5}, {{0, 0}, {5, 6}}, {5, 6}},
|
||||
|
|
Loading…
Reference in a new issue