0 . . . This is a Grid object with 4 rows and 4 columns (numbered 0 - 3). . . > . The mover '>' is at row 1, column 2, facing east. . . . . The obstacle '#' is at row 3, column 1 . # . . The other item '0' is at row 0, column 0The @ character indicates that the mover and an item (0) currently occupy the same position on the grid.
. empty spot on the grid 0 an item that can be placed, or picked up # a block (an obstacle). Mover cannot move through it < mover facing WEST > mover facing EAST ^ mover facing NORTH v mover facing SOUTH @ mover occupying same place as item (0)A printed space ' ' in a grid position represents a spot that the mover has already moved through when the path display is toggled on
You'll need the library cstdlib for the srand and rand functions. While it's not normally the best place to do it, you can go ahead and seed the random number generator here in the constructor in some appropriate way so that it's different for seperate program runs.
If you need a refresher on pseudo-random number generation, see this
notes set from COP 3014:
http://www.cs.fsu.edu/~myers/c++/notes/rand.html
You are being provided one starter test program, along with the sample output:
You can use this to help test your class, but keep in mind that this is NOT a comprehensive set of tests. It is a small program that builds a simple maze in a grid, then has the mover navigate through the maze to pick up an item. It also drops a couple of other items on the way.You can certainly add to this and/or write your own test programs to
help test your class features.
Write a main program in a file called trap.cpp that solves the following scenario, using your Grid class:
Giant Mole People have risen from their underground lairs and are taking over the world. You have been taken prisoner and placed in an underground jail cell. Since the Mole People are blind and don't know how to build doors, your cell has one open exit (no door). Since you are deep underground, it is completely dark and you cannot see. Your task is to escape your prison to join the human resistance!
Your program should ask the user to input the number of rows, then columns, for the grid. (Note that this is the ONLY keyboard input for this program). Create a grid with the specified number of rows and columns, using the constructor with two parameters -- (this is the one that should automatically create a fenced-in grid containing one exit and a randomly placed mover). Display the initial grid. Since the placement of the exit and the mover is random, execution of this program will look a little different every time. Your task is to escape the trap! You will need to create an algorithm that will instruct the mover to find its way to the exit. (Hint: Think about how to use the Predicate functions before you move). Upon reaching the exit, you should print a message of success, like "We escaped!", and then output the final position of the mover. Keep the path toggled ON. You only need to display the initial setup grid and the final grid for this program.
General Requirements:
Submit the following files through the web page in the usual manner:
grid.h grid.cpp trap.cpp