pacman/exercises/25/pacman_ai/README.md
2021-10-05 15:46:52 +02:00

1.7 KiB

< Back

Exercise: PacMan AI

Let's implement a naive AI for PacMan.

Background: PacMan Moves

At each intersection, check if there is a ghost directly inline with that path. If the path is free of ghosts, you are allowed to turn there. And if PacMan is moving in a direction, and a ghost enters his path, then pacman will reverse.

For example if pacman is at an intersection and can go either right or up, and there is a ghost in the path going right, then pacman will go up. Then while pacman is going up, a ghost enters that path, pacman will go back.

You only need to worry about the grid itself and any ghosts on the North/South/East/West axis of PacMan.

Exercise

  1. Implement PacManAI::pelletClosestToPacman and test your implementation with the test in testPacmanAI.cpp called "Find pellet closest to pacman"

Hint:

GridPosition PacManAI::pelletClosestToPacman(GridPosition pacmanGridPosition,
                                             std::vector<GridPosition> & pellets) {
  return {0, 0};
}
  1. Implement PacManAI::isValidMove and test your implementation with the test in testPacmanAI.cpp called "Is valid move"

Hint:

bool PacManAI::isValidMove(const Move & move) {
  return false;
}
  1. Implement PacManAI::optimalDirection and test your implementation with the test in testPacmanAI.cpp called "Is optimal direction"

Hint:

Direction PacManAI::optimalDirection(const std::array<Move, 4> & moves) {
  return Direction::NONE;
}