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

Operating systems assignment-1 binary record sorting in

Operating Systems Assignment- 1. Binary Record Sorting in Ascending Order| You will write a simple sorting program. This program should be invoked as follows: shell% ./fastsort -i inputfile -o outputfile The above line m ...

Programming assignment 1 grocery storethis assignment

Programming Assignment #1: Grocery Store This assignment attempts to serve as a refresher for concepts that I hope you learned in CS 122. In this assignment, you will be building a simple storefront for a small grocery s ...

Object oriented system analysis and design1non-functional

Object Oriented System Analysis and Design 1. Non-Functional Requirements a) Analysis of NFRs Analyse the Case Study documents and determine the non-functional requirements (NFRs) or system quality attributes necessary t ...

Csis program homeworkwrite a program where the user will

CSIS program homework Write a program where the user will enter a number between 1 and 50 representing a state. The program should display the full name of that state. Assume the states are in alphabetical order, that is ...

Questioncomplete tutorial 10 case problem 2 - ridgewood

Question: Complete Tutorial 10 Case Problem 2 - Ridgewood Herald Tribune found on pages 734-736 of your textbook. Complete the entire website assignment and upload your files to your 000WebHost account. After uploading t ...

Assignmentthis assignment will be marked out of 100 and

Assignment This assignment will be marked out of 100 and carries 30% of the overall module weighting. Your .java files and report for this part must be uploaded to WebLearn and submitted by 3pm on Wednesday 27th April 20 ...

1 implement dfs by using prolog2 implement bfs by using

1. Implement DFS by using PROLOG. 2. Implement BFS by using PROLOG. 3.  Solve the problem of Question 3 in Assignment 1 by using your PROLOG programs of DFS and BFS, respectively. Question 3 from Assignment 1 to Solve wi ...

Shell programmingyou have created the directory structure

Shell Programming You have created the directory structure and some base files to be used by the Web server and Web site. For the Web site to be created in a production environment, you need to package your commands in a ...

Programming assignment- implement a udp client and udp

PROGRAMMING ASSIGNMENT- Implement a UDP client and UDP server that support simple timeout-based retransmission with AIMD congestion control: -The client should send as many packets as are in its CURWIN (current window) a ...

Engineering programmingi need this now please accurate

Engineering programming I need this now please accurate answers and must be high rated Problem #1 Write a program that asks the user to input the number of miles and convert the miles to kilometers, and then print the ou ...

  • 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

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate