des/ndctt2021 #1

Merged
des merged 10 commits from des/ndctt2021 into main 2021-10-20 08:00:22 +00:00
2 changed files with 8 additions and 4 deletions
Showing only changes of commit 4b58b4115c - Show all commits

View file

@ -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> &) {
return {0, 0};
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.

View file

@ -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}},