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 ordered doublylinked listobjectivesto introduce the


Lab assignmentwe begin our investigation of object-oriented


Create a very basic calculator map out the numeric keypad

Create a very basic calculator, map out the numeric keypad (17 buttons) and an EditText view. If text is given, prompt the user with a message that complains about the error. Toast.makeToast(getApplicationContext() , "er ...

Assignment1 you are a manager who is employed by a game

Assignment 1. You are a manager who is employed by a game production company. Your team is responsible for coding one of the game modules. You have two newly hired programmers working for you who believe that the followi ...

Question 1 batteriesi want to use a galvanic cell to power

Question 1: Batteries I want to use a galvanic cell to power a 60-watt light bulb. Complete the following steps to determine how long the galvanic cell will power the light bulb before running out. a.) The galvanic cell ...

The car classdefine a class called car that implements the

The Car Class Define a class called "Car" that implements the parameterized Comparable interface. Each object of this class represents a type of car. Your class must provide all the methods in the public interface. Be su ...

Write a program which1 asks the user to enter a positive

Write a program which: 1. Asks the user to enter a positive integer greater than or equal to 0 2. Validates that the entry is a positive integer 3. Outputs the digits in reverse order with a space separating the digits 4 ...

Create a program that allows the user to enter sets of

Create a program that allows the user to enter sets of integer values, in any order.Per set of data,the program is to output the largest number. EXAMPLE 1 Given the set of supplied values:(1,-3,22,-30),the program should ...

Assignmentthe csit racing club is a group that runs amateur


Programming languages assignment write the following as

Programming Languages Assignment Write the following as Prolog rules:  1. Implement a rule "dogEnthusiast". Someone is a "dogEnthusiast" if they own AT LEAST TWO dogs. Assume that the only types of facts available are: " ...

  • 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


Ask Now Help with Problems, Get a Best Answer

WalMart Identification of theory and critical discussion


Section onea in an atwood machine suppose two objects of


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


Details on advanced accounting paperthis paper is intended


Create a provider database and related reports and queries
