-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
171 lines (146 loc) · 4.77 KB
/
main.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
166
167
168
169
170
171
//
// main.cpp
// Graphs
//
// Created by Kode Creer on 2/22/19.
// Copyright © 2019 Kode Creer. All rights reserved.
//
#include <iostream>
#include <vector>
#include "Graph.h"
#include <queue>
#include "SearchFunctions.h"
//#include "GraphOutput/GraphOutput.h"
#include <fstream>
#include <vector>
template <class Item>
void printGraphVisual(Graph<Item> g){
for (int i = 0; i < g.size(); ++i) {
std::cout << g[i].ID();
for (int b = 0; b < 4; ++b) {
switch (g[i].directions()[b]) {
case UP:
std::cout << "|^^^|";
break;
case DOWN:
std::cout << "|vvv|";
break;
case LEFT:
std::cout << "_<<<_";
break;
case RIGHT:
std::cout <<"_>>>_";
break;
default:
std::cout << "■■■■■";
break;
}
}
std::cout << std::endl;
}
}
template <class Item>
void printGraph(Graph<Item> g){
for (int i = 0; i < g.size(); ++i) {
std::cout << g[i].ID();
for (auto i : g.neighbors(i)) {
std::cout << " -> " << i;
}
std::cout << std::endl;
}
}
void printGraphLabels(Vertex<int> v){
std::cout << "Current Node : " << v.Value() << std::endl;
}
void on_graph_success(Vertex<int> v){
std::cout << "I found " << v.Value() << " which has an ID of " << v.ID() << std::endl;
}
//Same as the depth first funciton, but using a breadth first search instead
int main(int argc, const char * argv[]) {
// int tapestryRow, tapestryColumn;
// std::cout << "Welcome to the maze. The maze will be a 10 x 8 maze.\n:::\n You may place your tapestry and let the machine see if it can navigate out." << std::endl;
// do {
// std::cout << "Which row is it in? (A number between 1 and 10" << std::endl;
// std::cin >> tapestryRow;
// } while (tapestryRow < 1 || tapestryRow > 10);
//
// do {
// std::cout << "Which column is it in? (A number between 1 and 8)" << std::endl;
// std::cin >> tapestryColumn;
// } while (tapestryColumn < 1 || tapestryColumn > 8);
// std::ofstream points("Maze1.txt");
// for (auto i : directions) {
// for (int b = 0; b < 4; ++b) {
// points << i[b];
// }
// points << std::endl;
// }
// return 0;
const int numberAsciiAdjust = 48;
int mazeSize, mazeHeight, mazeWidth;
int k = 0;
std::ifstream points("Maze2/Maze.txt");
std::string height_str, width_str;
points >> height_str >> width_str;
mazeHeight = static_cast<int>(height_str[2] - numberAsciiAdjust);
mazeWidth = static_cast<int>(width_str[2] - numberAsciiAdjust);
mazeSize = mazeWidth * mazeHeight;
direction directions[mazeSize][4];
while (!points.eof()) {
std::string numStr;
points >> numStr;
for (int b = 0; b < 4; ++b) {
directions[k][b] = static_cast<direction>( numStr[b] - numberAsciiAdjust);
}
++k;
}
Graph<Vertex<int>> numsSys = Graph<Vertex<int>>();
for (int i = 0; i < mazeSize; ++i) {
Vertex<int> vert = Vertex<int>( i, directions[i] );
vert.ID() = i;
numsSys.add_vertex(vert);
}
//call a init edged function that goes through each edge
for (int i = 0; i < mazeSize; ++i) {
for (int b = 0; b < 4; ++b) {
switch (numsSys[i].directions()[b]) {
case DOWN:{
numsSys.add_edge(i, i+1, 1);
break;
}
case UP:{
numsSys.add_edge(i, i-1, 1);
break;
}
case LEFT:{
numsSys.add_edge(i, i-mazeHeight, 1);
break;
}
case RIGHT:{
numsSys.add_edge(i, i+mazeHeight, 1);
break;
}
case NONE:{
//do nothing
break;
}
}
}
}
printGraph(numsSys);
//The range of the maze is 0 to 15. You can use anyone but the BFS and it will work to traverse the maze.
//Remember that my maze is formated like this
/*
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
*/
const size_t start = 11;
const size_t end = 12;
depth_first(::printGraphLabels, ::on_graph_success, numsSys, start, end);
//breadth_first(::printGraphLabels, numsSys, numsSys.size()/2+9);
shortest_route(::printGraphLabels, numsSys, start, end);
std::cout<<std::endl;
return 0;
}