Ask Question, Ask an Expert


Ask Programming Language Expert


In this assignment you need to simulate a maze traversal using so called recursive backtracking (the algorithm is given below).

The grid of #s and 0s in the following Figure is a two-dimensional array representation of a maze. #s represent the walls of the maze, and the zeros represent locations in possible paths through the maze. In the maze, you can move one step at a time in the four directions: up, down, right, left, no “diagonal” moves are allowed. A move can be made only to the location in the array which contains a zero.

# # # # # # # # # # # #
# 0 0 0 # 0 0 0 0 0 0 #
0 0 # 0 # 0 # # # # 0 #
# # # 0 # 0 0 0 0 # 0 #
# 0 0 0 0 # # # 0 # 0 0
# # # # 0 # 0 # 0 # 0 #
# 0 0 # 0 # 0 # 0 # 0 #
# # 0 # 0 # 0 # 0 # 0 #
# 0 0 0 0 0 0 0 0 # 0 #
# # # # # # 0 # # # 0 #
# 0 0 0 0 0 0 # 0 0 0 #
# # # # # # # # # # # #

prepare the recursive function called mazeTraversal, to walk through the maze like the one shown above.

Function mazeTraversal must attempt to locate the exit; it must also place the character 'x' in each square in the path.

In mazeTraversal you need to implement the following recursive algorithm:

• From the current location in the maze, try to move one space in one of the four directions (down, right, up or left).
• If it is possible to move in at least one direction, call mazeTraversal recursively, passing the new location in the maze as the current location.
• If it is not possible to go in any direction, return to the previous location in the maze and try new direction from that location

This recursive algorithm finds the exit (assuming there is an exit). If there is no exit, you will arrive at the starting location again.
Program the function to display the maze after each move so that the user can see how the maze is solved. The final output of the maze must display the path that solves the maze.

1) Class Maze. The Maze class must have:

a) Two private instance variables – int size, char **maze;
b) Constructor “Maze(char **c, int size)” – takes as an argument an n-by-n two-dimensional character array which contains only #s and 0s.
c) Public function void mazeTraversal(int a, int b)” – tries to “solve” the maze. Parameters a, b represent the entry point to the maze. Recursive algorithm for the mazeTraversal is described in the previous section.
d) friend ostream &operator<<(ostream &stream, Maze &m) – to print maze m in a tabular format.
e) Private function void mazeGenerator()” – randomly creates an n-by-n (3010≤≤n) Maze object which has an entry point on the left side. The algorithm for mazeGenerator should be as follows:

• You start with 2-dimensional n-by-n array maze containing only #s, and then you “dig” your way through it until reaching a border, marking the visited cells with 0s.
• The entry point is maze[n/2][0]
• First move is to the right, after that you chose randomly any of four possible directions to move.
• The function stops when it reaches a border.

f) Default constructor Maze() – calls the mazeGenerator.

2) main() function.

In the main function you must create three Maze objects:

• One on the figure in the section 0.
• A 12-by-12 maze that has an entry point but does not have an exit. You should design it yourself.
• A randomly generated maze object
Then the mazeTraversal function must be called on each of the created objects.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M9681

Have any Question? 

Related Questions in Programming Language

Lab stackslab exerciseimplement the following classesclass

Lab: Stacks Lab Exercise: Implement the following classes: Class Course that includes three instance variables: private int ID; // course ID private String Name; // course name private Course next; // link next Your clas ...

Assignmentinstructions the following programming problem

Assignment Instructions: The following programming problem can be solved by a program that uses three basic tasks-Input Data, Process Data, and Output Results. To process the data, it uses loops, arrays, decisions, accum ...

Design an abstract class called shape this class must

Design an abstract class called Shape. This class must contain a single constructor that accepts a single numeric value that can be used to calculate various values, one of which is area. Include an abstract method calle ...

Figure is code to count the number of primes from 2 to n

Figure is code to count the number of primes from 2 to n, using the sieve method on a suitably large array a. That is, a[i] is TRUE at the end only if there is no prime p i or less that evenly divides i. We initialize al ...

Design and implement your own simple class to represent any

Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...) Your class should have a constructor, one additional method and at least one member variable ...

Provide a recursive definition of some sequence of numbers

Provide a recursive definition of some sequence of numbers. Choose one different from that of any posted thus far. Write a recursive method that given n, computes the nth term of that sequence. Also provide an equivalent ...

Using the machine model find the minimum initiation

Using the machine model, find the minimum initiation interval and a uniform schedule for the iterations, for the following loop: for(i =1; i A[i] = B[i-1] + 1; B[i] = A[i-1] +2; } Remember that the counting of iterations ...

Write a program containing two classes named student and

Write a program containing two classes named student and roster, respectively. The program will maintain a current roster of students within a given course. Student data for the program includes student ID, first name, l ...

Lab assignmentwe begin our investigation of object-oriented

Lab Assignment We begin our investigation of object-oriented programming by creating an object-oriented program with a class called Employee. You will create two objects based on the Employee class, along with a class th ...

Creating methodssince you have created the data objects for

Creating Methods Since you have created the data objects for Harbor View Mooring, you now need to create processes associated with each object. In order to keep with good object-oriented practices of implementation hidin ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen