I have maze.cpp file and maze.h file so I need to find path to the end of maze a
ID: 3864784 • Letter: I
Question
I have maze.cpp file and maze.h file so I need to find path to the end of maze and I stack there.
Using Stack and Using Queue
***Maze.cpp file***
#include <cstdlib>
using namespace std;
#include <iostream>
#include "maze.h"
int main(int argc, char **argv)
{
// Commented out to facilitate testing.
/*
if (argc != 2) {
std::cout << "USAGE: PathFinder <path>" << std::endl;
return -1;
}
*/
bool test_maze[15][15] = {{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}};
Maze maze(test_maze, 15, 15);
maze.print();
}
***Maze.h file***
#ifndef MAZE_H
#define MAZE_H
#endif /* MAZE_H */
enum Direction {
UP,
DOWN,
LEFT,
RIGHT
};
class Cell {
public:
int x, y;
bool wall;
bool visited;
Cell() {}
};
class Maze {
int width;
int height;
Cell **cells;
public:
Maze(char *path)
{
// TODO The Path Finding Algorithm Create a search list for positions yet to explore, add the entrance (0,0), to this list While the list is not empty Remove the next position from the search list If it is the exit position, [n-1, n-1], then a path is found, construct the path and return the path. Otherwise, mark the position as visited, add all valid up, right, down, or left neighbor positions to the search list (in that order) If the list is empty and the method has not returned, there is no path
}
// A constructor to facilitate testing.
Maze(bool maze[][15], int size_x, int size_y)
{
width = size_x;
height = size_y;
cells = new Cell*[width];
for(int i = 0; i < height; ++i)
cells[i] = new Cell[width];
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Cell *cell = &cells[i][j];
cell->x = i;
cell->y = j;
cell->wall = maze[i][j];
}
}
}
// Print the maze to stdout.
void print()
{
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (cells[i][j].wall) {
//std::cout << "";
std::cout<< "#";
} else {
std::cout << ".";
}
}
std::cout << std::endl;
}
}
};
Explanation / Answer
the input file is read and each cell contains an interger value that gets translated into its binary notation where starting from the left, each bit represents N E S W (North, east, south and west). How do i have it recognize where there are 1's and 0's ( 1 signifies a pathway within the room, 0...a c omplete wall) within the binary number. She provided us with the below header file....my questions is the "&" symbol does what? doorEncoding(which is the value of the cell) & 0x08...what does that mean? am thinking it compares the number's
MAZE.H;
MAZE.CPP:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.