subject

You are required to design a class for the grid and submit exactly three files: . . maze. h: class declaration maze. cpp : implementation of all methods defined in maze. h main. cpp: driver program that takes CLAs and uses the class Maze to generate output Your program will be compiled with the following line: $ g++ -std=c++11 -Wall main. cpp maze. cpp -o generator A common approach for maze generation involves removing interior walls iteratively. At each iteration a wall is removed to connect two adjacent cells. This iterative process must follow these rules: ⢠walls to be removed should be selected randomly. Use std:: rand() to generate random numbers and std::srand() to provide a seed to the random number generator ⢠there should be exactly one path connecting the starting and ending cells ⢠every cell must be reachable from the starting cell The algorithm below should be followed in your implementation. This is not the most efficient way to solve the problem of maze generation, however it is easy to understand and can be implemented with the support of simple data structures such as dynamic arrays ( std::vector in C++ ). The algorithm below should be followed in your implementation. This is not the most efficient way to solve the problem of maze generation, however it is easy to understand and can be implemented with the support of simple data structures such as dynamic arrays ( std::vector in C++ ). We strongly suggest you to trace this algorithm on paper using a small example (e. g. a 4 x 4 grid) until you fully understand how it works, before starting to code. create empty dynamic array A mark cell [0,0] as visited insert cell [0,0] at the end of 'A while 'A' is not empty 'current <- remove last element from A neighbors < current 's neighbors not visited yet if `neighbors is not empty insert current at the end of 'A 'neigh <- pick a random neighbor from `neighbors remove the wall between current' and 'neigh mark "neigh as visited insert "neigh' at the end of 'A endif endwhile In order to match the autograder tests, picking a random neighbor must follow this procedure: "check the neighbors of a cell in N-S-E-W order and append the ones that were not visited yet into an empty vector neighbors , then use the index idx below to pick a random neighbor with neighbors[idx] " idx = std::rand() / ((RAND_MAX + lu) / neighbors. size()); Your Task Your goal in this assignment is to develop a command line tool that will generate a random maze, given some options provided by the user. Command Line Arguments Your program must accept the following command line arguments: the seed value for the random number generator number of rows in the grid N > 0 number of cols in the grid M > 0 file name for the output The seed argument is very important as it initializes the random number generator. If you change the seed, you will generate a different maze. In your code make sure you call this function exactly once before generating the maze: std::srand(seed); The last argument will be used to save the generated maze into a text file. Note that you can provide any value as fname . See the example below: $ ./generator 10 10 example. txt Maze file format The file format for saving the maze is just a two dimensional array of integers, where each integer is used to represent a cell and its walls. Each integer in the matrix ranges from 0 to 16. The idea behind this representation is that the walls are encoded using 4 bits, and the ingeters are just their corresponding values in decimal notation. The figure below illustrates the encoding: N E N SE W ) 1 1 1 BITSTRING = 15 s Decinal walls 0111 = á U OD 3 = 1001 E9

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:00, alexj29227405
Write a method named addall that could be placed inside the hashintset class. this method accepts another hashintset as a parameter and adds all elements from that set into the current set, if they are not already present. for example, if a set s1 contains [1, 2, 3] and another set s2 contains [1, 7, 3, 9], the call of s1.addall(s2); would change s1 to store [1, 2, 3, 7, 9] in some order. you are allowed to call methods on your set and/or the other set. do not modify the set passed in. this method should run in o(n) time where n is the number of elements in the parameter set passed in.
Answers: 2
image
Computers and Technology, 23.06.2019 05:00, bellad0124outlookcom
In cell b18, enter a formula to calculate the amount budgeted for meals. this amount is based on the daily meal allowance and the total travel days (# of nights+1).
Answers: 1
image
Computers and Technology, 23.06.2019 17:20, Morehollie9428
What is the best assassins creed game?
Answers: 2
image
Computers and Technology, 24.06.2019 00:40, sierravick123owr441
Use a software program or a graphing utility with matrix capabilities to solve the system of linear equations using an inverse matrix. x1 + 2x2 − x3 + 3x4 − x5 = 6 x1 − 3x2 + x3 + 2x4 − x5 = −6 2x1 + x2 + x3 − 3x4 + x5 = 3 x1 − x2 + 2x3 + x4 − x5 = −3 2x1 + x2 − x3 + 2x4 + x5 = 5
Answers: 3
You know the right answer?
You are required to design a class for the grid and submit exactly three files: . . maze. h: class d...

Questions in other subjects:

Konu
Mathematics, 16.10.2020 18:01