diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a1ce6e7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "limits": "cpp" + } +} \ No newline at end of file diff --git a/lib/PacManAI.cpp b/lib/PacManAI.cpp index 2fc7b52..610f101 100644 --- a/lib/PacManAI.cpp +++ b/lib/PacManAI.cpp @@ -59,6 +59,7 @@ Direction PacManAI::chooseNewDirectionForPacMan(const PacMan & pacMan [[maybe_un return optimalDirection(possibleMoves); } +// todo: why is update taking pacman as argument instead of pacManAI void PacManAI::update(const PacMan & pacMan, const Pellets & pellets [[maybe_unused]]) { const GridPosition pacManGridPos = pacMan.positionInGrid(); diff --git a/test/exercises/21_exercises.md b/test/exercises/21_exercises.md index 135a209..1c199c0 100644 --- a/test/exercises/21_exercises.md +++ b/test/exercises/21_exercises.md @@ -9,18 +9,11 @@ ### Implement PacManAI::isValidMove -#### 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. +#### Background: PacManAI Moves +PacManAI is an alternative gameplay option to the regular PacMan. PacmanAI moves based on +`suggested_direction` rather than take an input from the keyboard. +The `suggested_direction` always starts from `Direction::Right` and is updated based on `chooseNewDirectionForPacMan`. -You only need to worry about the grid itself and any ghosts on the -North/South/East/West axis of PacMan. #### Exercise @@ -28,9 +21,9 @@ As a warmup exercise, implement [PacManAI::isValidMove][1] and test your implementation with the test in [testPacmanAI.cpp][2] called _"Is valid move"_ Note: `isValidMove` will be called 4 times in a loop. If the target cell is not -walkable the distance is set to infinity. +walkable the distance stays as infinity. -Note: Going backwards is not allowed, otherwise you'll go back and forwards between 2 +Note: Walking opposite to the suggested direction is not allowed, otherwise you'll go back and forwards between 2 pellets while playing the game. Note: The test is disabled, to enable the test remove the [!shouldfail] from the tags @@ -76,6 +69,8 @@ bool PacManAI::isValidMove(const Move & move) { if (!canWalk) { return false; } + + move.distanceToTarget = positionDistance(AI.position(), move.position); return true; } ``` @@ -88,18 +83,17 @@ bool PacManAI::isValidMove(const Move & move) { #### 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. +// suggestd Fix: +// The background is slightly misleading as optimalDirection is basically checking the direction for the shortest distance +rather than explicitly checking if there is a ghost inline. -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. +## Exercise +Find the direction of the pellets closest to PacManAI implement in `PacManAI::optimalDirection` -You only need to worry about the grid itself and any ghosts on the -North/South/East/West axis of PacMan. +PacManAI moves in `suggested_direction`. Optimize which direction is an optimal one by finding the pellet +closest to PacmanAI. -#### Exercise +#### Exercise 211 Implement [PacManAI::optimalDirection][1] and test your implementation with the test in [testPacmanAI.cpp][2] called _"Is optimal direction"_ @@ -127,7 +121,6 @@ Direction PacManAI::optimalDirection(const std::array & moves) { return dir; } -``` diff --git a/test/exercises/22_exercises.md b/test/exercises/22_exercises.md index 60622b1..5c8bd18 100644 --- a/test/exercises/22_exercises.md +++ b/test/exercises/22_exercises.md @@ -37,6 +37,7 @@ std::vector initialPelletPositions() { ```cpp std::vector initialPelletPositions() { + //could be renamed to pellet position std::vector positions; positions.reserve((ROWS * COLUMNS) / 3);