Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Figure below shows an example maze. In the maze, black cells are walls, which are obstacles that you can t move through. You can move
Figure below shows an example maze. In the maze, black cells are walls, which are obstacles that you
can
t move through. You can move on the white cells and you cannot move beyond the boundaries of
the maze. In each maze, the starting location will be the square of
Additionally there is also one
white cell labeled with F
This label shows the exit square of the maze. So
you must extract the path
from S to F
You can move in
directions; up
down left, right. These
directions will be represented by
characters U
D
L
and R
respectively
The solution for the maze shown above is
D D R R R R D D
which means move down
times then
move right
times and move down
times The maze a simple one way road and it has only one
solution: there is always one possible next square for each move.In Scheme, a maze will be represented in the form of a linked
list. Figure below shows how the maze in
the first page is represented in terms of a linked list in Scheme. Starting cell
has the letter S
the
finishing cell has the letter F and empty cells have the letter E
The walls have the letter
minus
The following function "buildMaze" on the left is given for you which takes a list of lists and creates
a maze using the lists. You can use this function to create different mazes in order to test your code.
On the right the code shows how the maze in the Figure above is created.
define
buildMaze rows
cond
null
rows
null
else
cons
buildMaze
cdr rows
car rows
define sampleMaze
buildMaze
S
E
E
E
E
E
E
E
F
Task
: Define two functions "getHeight" and "getWidth" which takes a maze as an input and
returns the height and the width of the maze.
getHeight sampleMaze
should return
getWidth sampleMaze
should return
Task
: Define a function "getLetter" which takes a maze, a row number and a column number.
Then it returns the letter from the maze on the corresponding location
row
column
getLetter sampleMaze
should return S
getLetter sampleMaze
should return E
getLetter sampleMaze
should return
getLetter sampleMaze
should return F
Task
: Define a function "solveMaze" which takes a maze and returns the solution for the maze.
solveMaze sampleMaze
should return
D D R R R R D D
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started