Remove part of the AI implementation
This commit is contained in:
parent
4aff1fa43e
commit
a835774f5a
2 changed files with 12 additions and 23 deletions
|
@ -14,38 +14,24 @@ Direction PacManAI::suggestedDirection() const {
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is not yet implemented.
|
||||||
|
// You will implement it as part of module 25.
|
||||||
GridPosition PacManAI::pelletClosestToPacman(GridPosition pacmanGridPosition,
|
GridPosition PacManAI::pelletClosestToPacman(GridPosition pacmanGridPosition,
|
||||||
std::vector<GridPosition> & pellets) {
|
std::vector<GridPosition> & pellets) {
|
||||||
|
|
||||||
auto pelletSort = [&pacmanGridPosition](GridPosition pelletA, GridPosition pelletB) {
|
return {0, 0};
|
||||||
double distanceA = positionDistance(pacmanGridPosition, pelletA);
|
|
||||||
double distanceB = positionDistance(pacmanGridPosition, pelletB);
|
|
||||||
return distanceA < distanceB;
|
|
||||||
};
|
|
||||||
std::sort(pellets.begin(), pellets.end(), pelletSort);
|
|
||||||
return pellets[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is not yet implemented.
|
||||||
|
// You will implement it as part of module 25.
|
||||||
bool PacManAI::isValidMove(const Move & move) {
|
bool PacManAI::isValidMove(const Move & move) {
|
||||||
const bool isOpposite = (move.direction == oppositeDirection(direction));
|
|
||||||
if (isOpposite) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
const bool canWalk = isWalkableForPacMan(move.position);
|
|
||||||
if (!canWalk) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is not yet implemented.
|
||||||
|
// You will implement it as part of module 25.
|
||||||
Direction PacManAI::optimalDirection(const std::array<Move, 4> & moves) {
|
Direction PacManAI::optimalDirection(const std::array<Move, 4> & moves) {
|
||||||
const auto optimalMove = std::min_element(moves.begin(), moves.end(), [](const auto & a, const auto & b) {
|
return Direction::NONE;
|
||||||
return a.distanceToTarget < b.distanceToTarget;
|
|
||||||
});
|
|
||||||
|
|
||||||
const auto & move = *optimalMove;
|
|
||||||
return move.direction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacManAI::update(const PacMan & pacMan, const Pellets & pellets) {
|
void PacManAI::update(const PacMan & pacMan, const Pellets & pellets) {
|
||||||
|
|
|
@ -5,4 +5,7 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
|
||||||
|
|
||||||
add_executable(pacman_tests ${sources})
|
add_executable(pacman_tests ${sources})
|
||||||
target_link_libraries(pacman_tests Catch2::Catch2 libpacman)
|
target_link_libraries(pacman_tests Catch2::Catch2 libpacman)
|
||||||
add_test(NAME pacman_tests COMMAND pacman_tests)
|
|
||||||
|
# This setup the tests on CI. We disable the AI tests
|
||||||
|
# because you will have to implement them.
|
||||||
|
add_test(NAME pacman_tests COMMAND pacman_tests "~[AI]")
|
||||||
|
|
Loading…
Reference in a new issue