maze

.h

School

Stanford University *

*We aren’t endorsed by this school

Course

120

Subject

Computer Science

Date

Oct 30, 2023

Type

h

Pages

4

Uploaded by JusticeKouprey15684

/** * @file maze.h * Square Maze implementation. * @date 12/07/2009 * @date 12/08/2009 */ #pragma once #include <vector> #include "cs225/PNG.h" #include "cs225/HSLAPixel.h" #include "dsets.h" #include <utility> #include <random> #include <iostream> /** * Each SquareMaze object represents a randomly-generated square maze and its * solution. * * (Note that by "square maze" we mean a maze in which each cell is a square; * the maze itself need not be a square.) */ class SquareMaze { private: int size_; std::mt19937 gen; // Defining Gen as private member var int mazeWidth; int mazeHeight; DisjointSets cellData; std::vector<std::vector<std::pair<bool, bool>>> wallData; // For backtracking & maze solution std::vector<std::vector<bool>> isVisited; // cs225::PNG mazeImage; public: // My Own //bool checkPoint(int neighborX, int neighborY) const; bool hasNoCycle(int x, int y) ; int calculateIndex(int current, int peek) const; /** * No-parameter constructor. * Creates an empty maze. */ SquareMaze(); /** * Makes a new SquareMaze of the given height and width. * * If this object already represents a maze it will clear all the * existing data before doing so. You will start with a square grid (like * graph paper) with the specified height and width. You will select * random walls to delete without creating a cycle, until there are no * more walls that could be deleted without creating a cycle. Do not * delete walls on the perimeter of the grid. * * Hints: You only need to store 2 bits per square: the "down" and
* "right" walls. The finished maze is always a tree of corridors.) * * @param width The width of the SquareMaze (number of cells) * @param height The height of the SquareMaze (number of cells) */ void makeMaze(int width, int height); /** * * This uses your representation of the maze to determine whether it is * possible to travel in the given direction from the square at * coordinates (x,y). * * For example, after makeMaze(2,2), the possible input coordinates will * be (0,0), (0,1), (1,0), and (1,1). * * - dir = 0 represents a rightward step (+1 to the x coordinate) * - dir = 1 represents a downward step (+1 to the y coordinate) * - dir = 2 represents a leftward step (-1 to the x coordinate) * - dir = 3 represents an upward step (-1 to the y coordinate) * * You can not step off of the maze or through a wall. * * This function will be very helpful in solving the maze. It will also * be used by the grading program to verify that your maze is a tree that * occupies the whole grid, and to verify your maze solution. So make * sure that this function works! * * @param x The x coordinate of the current cell * @param y The y coordinate of the current cell * @param dir The desired direction to move from the current cell * @return whether you can travel in the specified direction */ bool canTravel(int x, int y, int dir) const; /** * Sets whether or not the specified wall exists. * * This function should be fast (constant time). You can assume that in * grading we will not make your maze a non-tree and then call one of the * other member functions. setWall should not prevent cycles from * occurring, but should simply set a wall to be present or not present. * Our tests will call setWall to copy a specific maze into your * implementation. * * @param x The x coordinate of the current cell * @param y The y coordinate of the current cell * @param dir Either 0 (right) or 1 (down), which specifies which wall to * set (same as the encoding explained in canTravel). You only need to * support setting the bottom and right walls of every square in the grid. * @param exists true if setting the wall to exist, false otherwise */ void setWall(int x, int y, int dir, bool exists); /** * Solves this SquareMaze. * * For each square on the bottom row (maximum y coordinate), there is a * distance from the origin (i.e. the top-left cell), which is defined as
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: You are the HR consultant to a small business with about 40 employees. At the present time, the firm…
Q: Which of these junctions allows solutes and water to pass directly from one cell to another, without…
Q: Write a Java program, SortedIntegerList.java, that uses a linked list to store 100 random integer…
Q: The mean entry level salary of an employee at a company is $60,000. You believe it is lower for IT…
Q: Suppose a yttrium-88 nuclide transforms into a strontium-88 nuclide by absorbing an electron and…
Q: If 11.2 g of naphthalene, C 10H 8 (Molar mass= 128 g/mol), is dissolved in 107.8 g of chloroform,…
Q: Which of the following depends on temperature? Group of answer choices Molarity molality percent by…
Q: What are the three major mechanisms by which exercise increases glycolytic rate?
Q: Breslin Incorporated made a capital contribution of investment property to its 100-percent-owned…
Q: Implicit Differentiation using f, fy & f Let 20x² 1 dy dr dy Use partial derivatives to calculate at…
Q: d. K3PO4 The purple spheres represent particles of solute. Which compounds are represente (IV)? I…
Q: The records of Fremont Corporation’s initial and unaudited accounts show the following ending…
Q: b1. What are the tax consequences (amount and character of recognized gain or loss) of the…
Q: what happens when a changing magnetic field through a loop of wire a potential difference voltage…
Q: 15) What compound is produc 'N s treated with LiAlH4? -) CH3CH2CONH2 OCH3CH2CH2NH2 O CH3CH2CH2OH…
Q: If asteroid Toutatis were to pass somewhere within 24 x105 km of planet Syrene, what is the…
Q: What do we expect from schools? How do we know when a school is a "good school?"
Q: The fourth and final phase of the project life cycle.…
Q: Consider the reaction below. If you start with 5.00 moles of C produced? C3H8(g) + 5 O₂(g) → 3…
Q: Given: f(x)=-x^2-4x-3 What is the derivative of f(x) at a=-4?
Q: 3. Below is the graph of y=f(x), which is the derivative for some function f. Using the graph of the…
Q: Please PROBLEMS help with 7.14 Renal Disease The mean serum-creatinine level measured in 12 patients…