Ex 14: add isWall().
This commit is contained in:
parent
fe7551362d
commit
3779d1724f
2 changed files with 7 additions and 3 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue