forked from BYUCS235/Maze-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathfinder.cpp
144 lines (120 loc) · 3.33 KB
/
Pathfinder.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "Pathfinder.h"
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
Pathfinder::Pathfinder(){
for(int floor = 0; floor < FLOOR_SIZE; floor++){
for(int col = 0; col < COL_SIZE; col++){
for(int row = 0; row < ROW_SIZE; row++){
THE_MAZE[row][col][floor] = 1;
}
}
}
}
Pathfinder::~Pathfinder(){}
bool Pathfinder::importMaze(string file_name){
int floor, col, row;
int testVal;
ifstream inFile(file_name);
for(floor = 0; floor < FLOOR_SIZE; floor++){
for(col = 0; col < COL_SIZE; col++){
for(row = 0; row < ROW_SIZE; row++){
tempMaze[row][col][floor] = -1;
}
}
}
for(floor = 0; floor < FLOOR_SIZE; floor++){
for(col = 0; col < COL_SIZE; col++){
for(row = 0; row < ROW_SIZE; row++){
if(inFile.eof()){
return false;
}
inFile >> testVal;
if(testVal == 0 || testVal == 1){
tempMaze[row][col][floor] = testVal;
}
else{
return false;
}
}
}
}
if(tempMaze[0][0][0] != 1 || tempMaze[ROW_SIZE - 1][COL_SIZE - 1][FLOOR_SIZE - 1] != 1){
return false;
}
testVal = -1;
inFile >> testVal;
if(testVal != -1){
return false;
}
for(floor = 0; floor < FLOOR_SIZE; floor++){
for(col = 0; col < COL_SIZE; col++){
for(row = 0; row < ROW_SIZE; row++){
THE_MAZE[row][col][floor] = tempMaze [row][col][floor];
}
}
}
inFile.close();
return true;
}
string Pathfinder::toString() const{
int row;
int col;
int floor;
int valid = 1;
string retStr;
stringstream tempStream;
for(floor = 0; floor < FLOOR_SIZE; floor++){
for(col = 0; col < COL_SIZE; col++){
for(row = 0; row < ROW_SIZE; row++){
if(row == ROW_SIZE - 1){
tempStream << THE_MAZE[row][col][floor];
}
else{
tempStream << THE_MAZE[row][col][floor] << " ";
}
}
tempStream << endl;
}
if(floor < FLOOR_SIZE - 1){
tempStream << endl;
}
}
retStr = tempStream.str();
return retStr;
}
void Pathfinder::createRandomMaze(){
int row;
int col;
int floor;
for(floor = 0; floor < FLOOR_SIZE; floor++){
for(col = 0; col < COL_SIZE; col++){
for(row = 0; row < ROW_SIZE; row++){
THE_MAZE[row][col][floor] = rand() % 2;
}
}
}
THE_MAZE[0][0][0] = 1;
THE_MAZE[4][4][4] = 1;
}
vector<string>Pathfinder::solveMaze(){
// int row;
// int col;
// int floor;
// int tempInt;
// solution.clear();
// foundSolution = false;
// foundSolution = findPath(0,0,0, solution);
// for(floor = 0; floor < FLOOR_SIZE; floor++){
// for(col = 0; col < COL_SIZE; col++){
// for(row = 0; row < ROW_SIZE; row++){
// if(THE_MAZE[row][col][floor] == 2){
// THE_MAZE[row][col][floor] = 1;
// }
// }
// }
// }
return solution;
}