Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 2: Check out maze_data.hpp The file maze_data.hpp contains some data specifying a maze. There are two constant values MAZE_HEIGHT and MAZE_WIDTH that specify, respectively,

image text in transcribed

Step 2: Check out maze_data.hpp

The file maze_data.hpp contains some data specifying a maze. There are two constant values MAZE_HEIGHT and MAZE_WIDTH that specify, respectively, the height and width of the maze, in characters. Then, MAZE_DATA is a 2D array of characters representing the maze itself. There are 4 different characters used:

'#' this represents a wall in the maze

' ' (space) this represents an open space in the maze

'@' this represents the start of the maze

'^' this represents the end of the maze

In this lab, youre going to write a classes to represent this maze and an algorithm to explore it randomly, displaying the location of your random explorer in the maze after each step it takes.

Step 3: Implement classes to represent locations in your maze

You should write one abstract class called MazeLocation to represent a generic location in the maze. It should have the following public methods:

bool is_occupiable() this will indicate whether this location can be occupied by your maze explorer

char get_display_character() this will return the character that should be displayed to represent this location in the maze

After writing the MazeLocation class, you should write two classes that derive from it: Wall and OpenSpace.

The Wall class should represent a wall in the maze. A wall is never occupiable, and its display character is always '#'.

The OpenSpace class should represent an open space in your maze. An open space is always occupiable, but its display character might change depending on whether your explorer is in the space or whether it contains the end of the maze. To help with this, you should implement these additional methods for this class:

void set_has_explorer(bool) and bool has_explorer() use these functions to set and return a boolean class member that lets you know whether your explorer is in this space

void set_is_start(bool) and bool is_start() use these functions to set and return a boolean class member that lets you know whether this space is the start of the maze

void set_is_end(bool) and bool is_end() use these functions to set and return a boolean class member that lets you know whether this space is the end of the maze

Implement each of these classes in a separate set of .hpp and .cpp files. When youre done, add and commit your files to your git repo, and push them to your repo on GitHub.

Step 4: Write a Maze class to represent your maze

Now, you should write a Maze class to tie together your location classes above to represent a whole maze. Here are some things you should implement in your Maze class:

Your class should have a 2D vector of MazeLocation pointers to allow you to use polymorphism to represent your maze as a grid of Wall and OpenSpace objects: std::vector<:vector> > locations;

Your class should have a constructor that takes the following arguments: a 2D array of characters representing the maze (like MAZE_DATA from maze_data.hpp), an integer representing the mazes height, and an integer representing the mazes width. In this constructor, you should allocate your grid of locations and then loop through the maze data and allocate new Wall and OpenSpace objects to fill the grid, e.g.: this->locations[i][j] = new Wall(); or this->locations[i][j] = new OpenSpace();

You should write a destructor that frees the space you allocate in the constructor.

You should write a method to return the MazeLocation at a specified row and column of the grid: MazeLocation* get_location(int, int);

You should write a method to display the maze in the console: void display_maze(); This method can use the get_display_character() method to get the character to display for each of the individual locations.

Implement this class in a separate set of .hpp and .cpp files. When youre done, add and commit your new files to your git repo, and push them to your repo on GitHub.

Step 5: Write an application that creates and displays a maze

Now, write a small application that creates an object of your Maze class using the data in maze_data.hpp. Then, use the display_maze() method to display your maze. When youre done, add and commit your application code to your git repo, and push it to your repo on GitHub.

Step 6: Write an Explorer class that explores your maze

Now, write an Explorer class that will randomly explore your maze. Your class should have data members to hold the row and column of your explorers location in the maze. In addition, you should implement these methods:

char get_move() this method should randomly select a direction in which to move and return a character code (e.g. 'W', 'A', 'S', 'D') to indicate the direction chosen.

void set_location(int, int) this method should set the current location of your explorer.

int get_row() and int get_col() these methods should return the row and column, respectively, of your explorers current location.

Once your Explorer class is written, use it in your application to explore your maze object. Your exploration will probably happen within a small loop that does these things:

Calls your explorers get_move() method to get a move direction.

Uses a combination of the selected move direction and your explorers current location to figure out the row and column of the space to which the explorer is trying to move.

Uses your Maze classs get_location() method to get the MazeLocation object representing the space to which the explorer is trying to move.

Calls the is_occupiable() method on that MazeLocation object to see if the explorer can actually move there.

Calls the explorers set_location() method to update its location if the space to which its trying to move is, in fact, occupiable.

Calls the is_end() method on the MazeLocation object to see if the explorer has reached the end of the maze.

If its helpful, feel free to use the following function to implement a brief delay at each iteration of the main loop, so you can see the Explorer move around the maze:

#include

void sleep (float sec) {

clock_t t0 = clock(), t1 = t0;

while (t1 - t0

t1 = clock();

}

}

If you want to use this maze to, for example, have a 10 millisecond delay between iterations of the loop, you can call it like this:

sleep(0.01);

Once everything is working, add your new files and commit your changes to your git repo, and push everything to GitHub.

Grading Criteria

Thats it! After youre done with your lab, make sure you get it checked off by your TA so that you get points for it. If you dont get your work checked off, youll receive a zero for the lab, and we wont be able to change your grade, since well have no way to know whether or not you were at the lab.

This lab is worth 10 points total. Heres the breakdown:

3 points: MazeLocation, Wall, and OpenSpace classes

4 points: Maze class and application displaying the maze

3 points: Explorer class

#ifndefMAZE. DATAHPP - - #defineMAZEDATAHPP - - - #define MAZEHEIGHT 16 - #define MAZE WIDTH 16 const char* MAZE-DATA[MAZE. HEIGHT] { = 3; #endif #ifndefMAZE. DATAHPP - - #defineMAZEDATAHPP - - - #define MAZEHEIGHT 16 - #define MAZE WIDTH 16 const char* MAZE-DATA[MAZE. HEIGHT] { = 3; #endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

=+c) Why is this t-statistic negative?

Answered: 1 week ago