Ex 14: add isWall().

This commit is contained in:
Dag-Erling Smørgrav 2021-10-18 13:27:30 +02:00
parent fe7551362d
commit 3779d1724f
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]);
}
bool isWall(GridPosition point) {
return cellAtPosition(point) == Cell::wall;
}
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) {
const Cell cell = cellAtPosition(target_position);
if (cell == Cell::wall)
if (isWall(target_position))
return false;
return isEyes || isInPen(current_position) || !isInPen(target_position);
}

View File

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