
Concept explainers
JAVA Project
18.20 (Maze Traversal Using Recursive Backtracking) The grid of #s and dots (.) in Fig. 18.23 is
a two-dimensional array representation of a maze. The #s represent the walls of the maze, and the
dots represent locations in the possible paths through the maze. A move can be made only to a location
in the array that contains a dot.
Write the recursive method (mazeTraversal) to walk through mazes like the one in Fig. 18.23.
The method should receive as arguments a 12-by-12 character array representing the maze and the
current location in the maze (the first time this method is called, the current location should be the
entry point of the maze). As mazeTraversal attempts to locate the exit, it should place the character
x in each square in the path. There's a simple
finding the exit (assuming there's an exit). If there's no exit, you'll arrive at the starting
location again. The algorithm is as follows: From the current location in the maze, try to move one
space in any of the possible directions (down, right, up or left). If it's possible to move in at least
one direction, call mazeTraversal recursively, passing the new spot on the maze as the current spot.
If it's not possible to go in any direction, "back up" to a previous location in the maze and try a new
direction for that location (this is an example of recursive backtracking).
display the maze after each move so the user can watch as the maze is solved. The final output of
the maze should display only the path needed to solve the maze—if going in a particular direction
results in a dead end, the x's going in that direction should not be displayed. [Hint: To display only
the final path, it may be helpful to mark off spots that result in a dead end with another character
(such as '0').]
18.21 (Generating Mazes Randomly) Write an method mazeGenerator that takes as an argument a
two-dimensional 12-by-12 character array and randomly produces a maze. The method should also
provide the starting and ending locations of the maze. Test your method mazeTraversal from
Exercise 18.20, using several randomly generated mazes.
![18.20 (Maze Traversal Using Recursive Backtracking) The grid of #s and dots (.) in Fig. 18.23 is
a two-dimensional array representation of a maze. The #s represent the walls of the maze, and the
dots represent locations in the possible paths through the maze. A move can be made only to a lo-
cation in the array that contains a dot.
#3
# # #
# #
# #
#3
# #
# # # # # #
# #
# #
Fig. 18.23 | Two-dimensional array representation of a maze.
Write a recursive method (mazeTraversal) to walk through mazes like the one in Fig. 18.23.
The method should receive as arguments a 12-by-12 character array representing the maze and the
current location in the maze (the first time this method is called, the current location should be the
entry point of the maze). As mazeTraversal attempts to locate the exit, it should place the charac-
ter x in each square in the path. There's a simple algorithm for walking through a maze that guar-
antees finding the exit (assuming there's an exit). If there's no exit, you'll arrive at the starting
location again. The algorithm is as follows: From the current location in the maze, try to move one
space in any of the possible directions (down, right, up or left). If it's possible to move in at least
one direction, call mazeTraversal recursively, passing the new spot on the maze as the current spot.
If it's not possible to go in any direction, “back up" to a previous location in the maze and try a new
direction for that location (this is an example of recursive backtracking). Program the method to
display the maze after each move so the user can watch as the maze is solved. The final output of
the maze should display only the path needed to solve the maze-if going in a particular direction
results in a dead end, the x's going in that direction should not be displayed. [Hint: To display only
the final path, it may be helpful to mark off spots that result in a dead end with another character
(such as '0').]
18.21 (Generating Mazes Randomly) Write a method mazeGenerator that takes as an argument a
two-dimensional 12-by-12 character array and randomly produces a maze. The method should also
provide the starting and ending locations of the maze. Test your method mazeTraversal from
Exercise 18.20, using several randomly generated mazes.
#非中
%23
共 韩电 鞋
%23
%23
%23
%23
共 牡](https://content.bartleby.com/qna-images/question/55cdcfa4-aa98-41de-af44-dd41b27848ec/559a0602-212d-4bd2-94e6-4e328dc5873c/pczg8kd_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 7 images

- ii) In JAVA language input the elements of an integer array A of size 10 and find the count of all hills in the array. A[i] is a Hill if A[i-1]A[i+1]. A[i] >= 0 All elements of the array are unique.arrow_forward13) What's a Map? Homework • Unanswered Select all true statements from the below. Multiple answers: Multiple answers are accepted for this question Select one or more answers and submit. For keyboard navigation. SHOW MORE v a The idea of a map is to be able to look up one value with another. Often the lookup value is called the key and the looked-up value is called simply the value. As such, we see that any data structure essentially performs the actions required of a map.arrow_forwardWritten explaination requiredarrow_forward
- Java - Gift Exchange *** Please include UML Diagram and notes in code Minimum requirements are: At least 1 loop An Array or ArrayList At least 3 Java classes Use methods I am trying to make it so that the program will: Prompt for the number of people included in exchange - If not even it will state that there has to be an even number and ask for the number of people included again (loops). Prompt to enter a participant's first name Prompt for the participant's age Print out the random matching of participants so that everyone gets a gift and everyone gives a gift. Please include UML Diagramarrow_forwardArtificial Intelligence (Part - 2) ==================== The Towers of Hanoi is a famous problem for studying recursion incomputer science and searching in artificial intelligence. We start with N discs of varying sizes on a peg (stacked in order according to size), and two empty pegs. We are allowed to move a disc from one peg to another, but we are never allowed to move a larger disc on top of a smaller disc. The goal is to move all the discs to the rightmost peg (see figure). To solve the problem by using search methods, we need first formulate the problem. Supposing there are K pegs and N disk. (2) What is the size of the state space?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





