-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
143 lines (116 loc) · 4.61 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
#include "node.h"
#include "scene.h"
#include <iostream>
#include <list>
#include <queue>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
template<typename T>
void appendNeigbors(list<string> places,Node<T> *basePlace){
for(list<string>::iterator it=places.begin();
it!=places.end();
++it)
basePlace->addNode(new Node<T>(*it));
}
template<typename T>
void addNodesQueue(queue<Node<T>*> &queueNodes,list<Node<T>*> nodes){
for(typename list<Node<T>*>::iterator it=nodes.begin();
it!=nodes.end();
++it){
cout<<"I can go to "<<(*it)->getName()<<endl;
queueNodes.push(*it);
}
}
bool visited(vector<string> nodesVisited,string item){
return find(nodesVisited.begin(),nodesVisited.end(),item) != nodesVisited.end();
}
// Walk All Nodes using Best First Search strategy
template<typename T>
void walkNodes(Node<T> *basepNode){
cout<<"Walk nodes in Best First Search strategy"<<endl;
queue<Node<T> *> queueNodes;
vector<string> nodesVisited;
list<Node<T>*> nodes=basepNode->getListNodes();
cout<<"From "<<basepNode->getName()<<endl;
nodesVisited.push_back(basepNode->getName());
addNodesQueue(queueNodes,nodes);
while(!queueNodes.empty()){
Node<T>* node=queueNodes.front();
queueNodes.pop();
list<Node<T>*> newListNodes=node->getListNodes();
if(newListNodes.size()>0 and !visited(nodesVisited,node->getName())){
cout<<"From "<<node->getName()<<endl;
addNodesQueue(queueNodes,newListNodes);
}
nodesVisited.push_back(node->getName());
}
cout<<" "<<endl;
cout<<"Printing Visited Nodes"<<endl;
for(auto it=nodesVisited.begin();
it!=nodesVisited.end();
++it)
cout<<*it<<endl;
}
class Connection {
public:
Connection(string o,string d,string c,bool v,bool op):
origin_id(o),destiny_id(d),cardinal(c),visible(v),open(op){}
string origin_id;
string destiny_id;
string cardinal;
bool visible;
bool open;
};
int main(){
pIntNode nodeBase = new intNode("home");
list<string> placesToGo = {"tesco","office","mall"};;
appendNeigbors(placesToGo,nodeBase);
pIntNode tescoNode = nodeBase->getNeighbourName("tesco");
pIntNode officeNode = nodeBase->getNeighbourName("office");
pIntNode mallNode = nodeBase->getNeighbourName("mall");
appendNeigbors({"bakery","beberages","meats"},tescoNode);
appendNeigbors({"desktop","kitchen","cantine","toilet"},officeNode);
appendNeigbors({"McDonals","Cafe","Wilko"},mallNode);
pIntNode wilkoNode = mallNode->getNeighbourName("Wilko");
appendNeigbors({"electricity","painting","cars"},wilkoNode);
walkNodes<int>(nodeBase);
//// Test NodeScene
cout<<" "<<endl;
cout<<"Testing NodeScene"<<endl;
map<string,NodeScene*> myWorld;
// TODO: Load scenes names and ids from somewhere
list<pair<string,string> > mySceneNamesIds = {{"Entry to Great Cave!",
"great_cave_node"},
{"Interior of Great Cave!",
"int_great_cave"},
{"Entry tunnels into the dark deep.",
"entry_tunnels_dark_deep"}};
for(auto it=mySceneNamesIds.begin();
it!=mySceneNamesIds.end();
++it){
Scene newScene(it->first); // TODO: Scene build can be as complex as you want
myWorld[it->second] = new NodeScene(it->second,newScene);
}
// TODO: Load connections from somewhere
Connection connect1("great_cave_node","int_great_cave","north",true,true);
Connection connect2("int_great_cave","entry_tunnels_dark_deep","east",true,true);
list<Connection> listConnections;
listConnections.push_back(connect1);
listConnections.push_back(connect2);
for(auto it=listConnections.begin();
it!=listConnections.end();
++it){
string origin=(*it).origin_id;
string destiny=(*it).destiny_id;
string cardinal=(*it).cardinal;
bool visible=(*it).visible;
bool open=(*it).open;
//cout<<"origin"<<origin<<endl;
NodeScene *myNodeSceneOrigin = myWorld[origin];
NodeScene *myNodeSceneDestiny = myWorld[destiny];
myNodeSceneOrigin->setExit(myNodeSceneDestiny,cardinal,visible,open);
}
walkNodes(myWorld["great_cave_node"]);
}