-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
72 lines (61 loc) · 1.59 KB
/
main.cpp
File metadata and controls
72 lines (61 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Project Name: 235 Lab 07 - 3D Maze
Description: Find a path through a 3-D Maze
*/
#ifdef _MSC_VER
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define VS_MEM_CHECK _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#else
#define VS_MEM_CHECK
#endif
#include <iostream>
#include <fstream>
#include "Maze.h"
using namespace std;
//enum { OPEN, BLOCKED };
int main(int argc, const char * argv[]) {
VS_MEM_CHECK; //Checks for Memory Leaks
//Opens files
if (argc < 3)
{
cerr << "Please provide name of input and output files\n";
return 1;
}
cout << "Input file: " << argv[1] << endl;
ifstream in(argv[1]);
if (!in)
{
cerr << "Unable to open " << argv[1] << " for input\n";
return 1;
}
cout << "Output file: " << argv[2] << endl;
ofstream out(argv[2]);
if (!out)
{
in.close();
cerr << "Unable to open " << argv[2] << " for output\n";
}
int height;
int width;
int numLayers;
int value;
in >> height >> width >> numLayers;
Maze maze(height, width, numLayers);
//Sets values for maze
for (int k = 0; k < numLayers; k++) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
in >> value;
if (value == 0) { maze.setValue(i, j, k, OPEN);}
else { maze.setValue(i, j, k, BLOCKED); }
}
}
}
//Finds maze path, if possible and outputs original and solved maze
maze.find_maze_path();
out << maze;
in.close();
out.close();
return 0;
}