Ex 25: Implement PacManAI::optimalDirection().

This commit is contained in:
Dag-Erling Smørgrav 2021-10-19 10:48:26 +02:00
parent b97e1c6f2c
commit 30ae28cfc7
1 changed files with 5 additions and 2 deletions

View File

@ -33,8 +33,11 @@ bool PacManAI::isValidMove(const Move & move) {
// This function is not yet implemented.
// You will implement it as part of module 25.
Direction PacManAI::optimalDirection(const std::array<Move, 4> &) {
return Direction::NONE;
Direction PacManAI::optimalDirection(const std::array<Move, 4> & moves) {
auto bestMove = std::min_element(moves.begin(), moves.end(), [](Move a, Move b) {
return a.distanceToTarget < b.distanceToTarget;
});
return bestMove->direction;
}
void PacManAI::update(const PacMan & pacMan, const Pellets & pellets) {