-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabyrinth.cpp
166 lines (135 loc) · 2.41 KB
/
labyrinth.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <stdlib.h>
#include "graph.hpp"
using namespace std;
int main()
{
bool graph_bool[r][c];
int graph_int[r][c];
vector<Node> nodes;
char * test;
int i = 0;
int j = 0;
int numberNodes;
ifstream File;
File.open("random_maze.txt");
char output[100];
if (File.is_open()) {
while (!File.eof()) {
File >> graph_bool[i][j] ;
j++;
if(j == c)
{
i +=1;
j = 0;
}
}
}
File.close();
Graph graph = generateGraph(graph_bool, r, c);
numberNodes = graph.numberNodes();
cout << numberNodes << endl;
ofstream outFile;
outFile.open("maze_output.txt");
nodes = graph.getNodes();
for(int i = 0; i < r; i++)
{
for(int j = 0; j < r; j++)
{
graph_int[i][j] = graph_bool[i][j];
}
}
for(int i = 0 ; i < nodes.size(); i++)
{
int x = nodes[i].getX();
int y = nodes[i].getY();
graph_int[x][y] = 2;
}
//int ** neighbors = graph.getNeighbors();
char option;
cout << "Show best path? (y/n)";
cin >> option;
if(option == 'y')
{
int path_node1;
int path_node2;
cout << " Enter the nodes in the best path: " << endl;
cout << "Node index: " << endl;
cin >> path_node1;
cout << "Node index: " << endl;
cin >> path_node2;
while(path_node1 != -1)
{
int x1 = nodes[path_node1].getX();
int y1 = nodes[path_node1].getY();
int x2 = nodes[path_node2].getX();
int y2 = nodes[path_node2].getY();
graph_int[x1][y1] = 2;
graph_int[x1][y1] = 2;
if(y1 == y2)
{
if(x1 < x2)
{
int i = x1 ;
while(i != x2)
{
graph_int[i][y1] = 2;
i++;
}
}
else
{
int i = x2 ;
while(i != x1)
{
graph_int[i][y1] = 2;
i++;
}
}
}
if(x1 == x2)
{
if(y1 < y2)
{
int i = y1 ;
while(i != y2)
{
graph_int[x1][i] = 2;
i++;
}
}
else
{
int i = y2 ;
while(i != y1)
{
graph_int[x1][i] = 2;
i++;
}
}
}
path_node1 = path_node2;
cout << "Node index: " << endl;
cin >> path_node2;
}
}
for(int i = 0; i < r ; i++)
{
for(int j = 0 ; j < c; j++)
{
outFile << graph_int[i][j] << " ";
}
outFile << "\n";
}
// for(int i = 0; i < numberNodes; i++)
// {
// for(int j = 0; j< 4 ; j++)
// {
// cout << neighbors[i][j] << " ";
// }
// cout << "\n";
// }
}