Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can somebody help me solve this rat-in-a-maze C++ program using stl stacks data structure , HERE ARE THE INSTRUCTIONS : In this assignment you will

Can somebody help me solve this rat-in-a-maze C++ program using stl stacks data structure , HERE ARE THE INSTRUCTIONS :

In this assignment you will simulate a rat-in-a-maze, and you will use a Stack to a path through the maze. You will use the STL stack data structure.Suppose that the maze is to be modeled as an n by m matrix with position (1,1) of the matrix representing the entrance and position (n,m) representing the exit. n and m are, respectively, the number of rows and columns in the maze. Each maze position is described by its row and column intersection. The matrix has a 1 in position (i, j) if there is an obstacle at the corresponding maze position. Otherwise, there is a 0 at this matrix position. Below is an illustration of a sample maze and a corresponding matrix representation of that maze.

You are to write a program to solve the rat-in-a-maze problem. You may assume that the mazes for which your program is to work are sufficiently small so that the entire maze can be represented in the memory of the target computer. Your program will be read in command line parameters containing filenames of maxes to process. The first line of the maze file will be ROW_COUNT COLUMN_COUNT. The proceeding lines with be a matrix of 1's and 0's depending on if it is blocked or not. See one of the provided maze text files. You can assume that the input files have correct syntax. The command line arguments will be received as follows: mazefile1 [mazefile2] ... [mazefilen]

To find the path through the maze you may proceed as follows: Begin with the entrance as your starting position. If the present position is the exit, then you have found a path and you are done. If you are not at the exit, then block the present position (i.e., place an obstacle there) so as to prevent the search from returning here. Next see whether there is an adjacent maze position that is not blocked. If so, move to this new adjacent position and attempt to find a path from there to the exit. If unsuccessful, attempt to move to some other unblocked adjacent maze position and try to find a path from there. To facilitate this move, save the current position on a Stack before advancing to a new adjacent position. If all adjacent unblocked positions have been tried and no path is found, there is no path from entrance to exit in the maze. Remember that from interior (i.e. nonboundary) positions of the maze, four moves are possible: right, down, left, and up. From positions on the boundary of the maze, either two or three moves are possible. To avoid having to handle positions on the boundaries of the maze differently from interior positions, you may find it useful to surround the entire maze with a wall of obstacles. For an m by n maze, this wall will occupy rows 0 and m + 1 and columns 0 and n + 1 of the matrix.

HERES A CLASS THAT WOULD HELP TO DISPLAY THE OUTPUT(THE PATH THAT IT TOOK)

// FILE: position.h (part of the namespace p3_maze) version 0.2 // PROVIDES: A class to keep track of one maze location. Row, Column, and steps from entry // // CONSTRUCTOR for the node class: // position(const int &r=0,const int &c=0,const int &s=0) { setpos(r,c);nsteps=s; } // Postcondition: The position contains the default items // // MODIFICATION MEMBER FUNCTIONS // void row(const int &r) // Precondition: none // Postcondition: row member variable updated // // void col(const int &c) {pcol = c;} // Precondition: none // Postcondition: col member variable updated // // void setpos(const int &r, const int &c) {prow=r; pcol=c;} // Precondition: none // Postcondition: Member variables row and column are updated // // void stepup() {nsteps++;} // Precondition: None // Postcondition: steps is incremented by one // // CONSTANT MEMBER FUNCTIONS // int row() const {return prow;} // Precondition: none // Postcondition: Returns the row member variable value // // int col() const {return pcol;} // Precondition: none // Postcondition: Returns the column member variable value // // int steps() const {return nsteps;} // Precondition: None // Postcondition: Returns the # of steps from entry #ifndef DS_POSITION #define DS_POSITION #include namespace ds_maze { class position { public: position(const int &r=0,const int &c=0,const int &s=0) { setpos(r,c);nsteps=s; } // MODIFICATION MEMBER FUNCTIONS void row(const int &r) {prow = r;} void col(const int &c) {pcol = c;} void setpos(const int &r, const int &c) {prow=r; pcol=c;} void stepup() {nsteps++;} // CONSTANT MEMBER FUNCTIONS int row() const {return prow;} int col() const {return pcol;} int steps() const {return nsteps;} private: int prow, pcol,nsteps; }; } #endif 

AND HERES HOW THE FINAL OUTPUT SHOULD LOOK, AFTER RUNNING IT .... THNAKS IN ADVANCE I REALLY NEED HELP WITH THIS ASSIGNMENT GUYS .

REMEMBER THAT THE MAZES ARE GONNA BE READ IN FROM A EXTERNAL .TXT FILE :

THE FIRST MAZE1.TXT SHOULD LOOK LIKE THIS

image text in transcribed

image text in transcribed

0001000 0111110 0000000 0000000 0111110 0000010 1111010 0000010 70111110 70000000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago