Given a two-dimensional array (the maze) and an array of steps, implement a solution to verify whether or not the player escaped the labyrinth.
- The solution should output "Escaped" if the player reaches the maze's exit.
- The solution should output "Dead" if the player hits a wall or goes outside the maze border.
- The solution should output "Lost forever" if the player does not reach the maze's exit after taking all their steps.
The two-dimensional data structure that represents the maze looks like this:
[
[1, 1, 1, 1, 1, 1, 1, 1, 0, 1],
[1, 3, 1, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 0, 0, 0, 0],
[1, 0, 1, 0, 1, 0, 1, 1, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 1, 1, 0, 1, 1, 1, 1, 2, 1]
]
// 0 = Safe place to walk
// 1 = Wall
// 2 = Player start point
// 3 = Maze exit
The list of steps will look like the following:
["N", "W", "W", "W", "N", "N", "N", "N", "W", "W", "S", "S", "S", "S", "W", "W", "N", "N", "N", "N", "N", "N", "N"]
// N = North
// E = East
// W = West
// S = South
Using the maze above, if the player's first step is S
, the output should be "Dead" as they leave the maze borders. If the first step is E
or W
, the player is also dead as they hit a wall. If the first step is N
, they are still in the game, and the program can execute the next step.