Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All I need you to do is write a maze traverser in C program. The input will be the parameters of a rectangular maze followed

All I need you to do is write a maze traverser in C program. The input will be the parameters of a rectangular maze followed by a character representation of the maze itself. The output of your program will be the maze with a path from entry point to exit point.

Here are some Specification of the program.

Your maze traverser will accept parameters and a rectangular maze through standard input. The first two parameters will be the number of rows and columns in the maze. The next two parameters will be the row and column of the entry point. The last two parameters will be the row and column of the exit point. The parameters will be followed by the character representation of the maze. Your program will draw a path from entry point to exit point.

The maze will be a rectangular grid of blocks and floor panels. A block will be a (hashtag), a floor panel will be a blank. The walls of the maze will be constructed from blocks and the floor from floor panels. Your traverser can move freely from floor panel to adjacent floor panel, but it will not be possible to walk through the walls.

You can drop a marker on any floor panel to show a step in your path. A marker can be any character except a block or a floor panel. You can also pick up a marker and replace it with a floor panel.

You can touch the walls, but you cannot alter the walls, so dont even think about it. The walls are too high to jump over, so that option is out as well. No digging under the walls, as there are giant carnivorous moles down there.

In a real-life maze, you could enter the maze, put one hand on the wall (left or right) and start walking. As long as you never stop touching the wall with that hand, you will make your way to the exit.

Your algorithmic maze traverser can be right- or left-handed. The right-handed traverser always wants to turn to the right, the left-handed traverser always wants to turn to the left.

It would be good to decide on a convention for directions in the maze. I went with North, South, East and West for a rectangular maze. You traverser will have to know the row and column of its current location as well as the direction the traverser is facing/going.

The maze traverser can change direction as needed. A right-handed traverser facing north would turn to the east. A left-handed traverser facing north would turn to the west. The sequence of turns for a right-handed traverser would be a circular sequence of north, east, south, west and then back to north. For a left-handed traverser, the sequence would be north, west, south, east and then back to north.

Your traverser would start at the entry point coordinates. Based on the entry point coordinates, the traverser would have to determine its initial direction of travel. A traverser entering through a west wall would be traveling east. (What rule would you infer here?) The traverser then takes a step in that direction. At the new location, the traverser tries to determine the next step. A left-handed traverser facing east will reach to the north.

If there is no wall to the north, the traverser turns to the north and takes a step to the north. If there is a wall to the north, the left-handed traverser then turns to the right and tries the wall to the east. The traverser keeps turning until it finds a location it can step to next. (What behavior would you infer for a right-handed traverser?)

The traverser builds a path by putting down some sort of marker on each floor panel the traverser steps on. Of course, the never-take-your-hand-off-the-wall approach means that the traverser will retrace some of its steps. Before putting down a marker, the traverser should look at the floor panel. If there is no marker there, go ahead and put a marker down. If there is a marker there already, the traverser should pick it up. The traverser gets a five-cent deposit on all returned markers.

Maze traversal ends when the traverser reaches the exit point coordinates.

Calculate the number of steps on the final path from entry to exit. You can also print out the maze as colored blocks. See the resource on printing stuff in color. Another option would be to print the maze after every step. If you use the escape sequence TBA to put the cursor back at the top left corner of the screen. Print the sequence before every maze reprint to get an interesting effect.

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

Is a circle a special type of ellipse? Why or why not?

Answered: 1 week ago

Question

Communicate with intercultural audiences.

Answered: 1 week ago