Ex 14: add isWall().

This commit is contained in:
Dag-Erling Smørgrav 2021-10-18 13:27:30 +02:00
parent 34445c7540
commit b9354e3dd1
2 changed files with 7 additions and 3 deletions

View file

@ -59,13 +59,16 @@ static Cell cellAtPosition(GridPosition point) {
return Cell(board[point.y][point.x]); return Cell(board[point.y][point.x]);
} }
bool isWall(GridPosition point) {
return cellAtPosition(point) == Cell::wall;
}
bool isWalkableForPacMan(GridPosition point) { bool isWalkableForPacMan(GridPosition point) {
return cellAtPosition(point) != Cell::wall && cellAtPosition(point) != Cell::pen; return !isWall(point) && !isInPen(point);
} }
bool isWalkableForGhost(GridPosition target_position, GridPosition current_position, bool isEyes) { bool isWalkableForGhost(GridPosition target_position, GridPosition current_position, bool isEyes) {
const Cell cell = cellAtPosition(target_position); if (isWall(target_position))
if (cell == Cell::wall)
return false; return false;
return isEyes || isInPen(current_position) || !isInPen(target_position); return isEyes || isInPen(current_position) || !isInPen(target_position);
} }

View file

@ -8,6 +8,7 @@
namespace pacman { namespace pacman {
bool isWall(GridPosition point);
bool isWalkableForPacMan(GridPosition point); bool isWalkableForPacMan(GridPosition point);
bool isWalkableForGhost(GridPosition target_position, GridPosition current_position, bool isEyes); bool isWalkableForGhost(GridPosition target_position, GridPosition current_position, bool isEyes);
bool isInPen(GridPosition point); bool isInPen(GridPosition point);