-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSolver.cpp
More file actions
46 lines (37 loc) · 1.42 KB
/
Copy pathSolver.cpp
File metadata and controls
46 lines (37 loc) · 1.42 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
#include "Globals.hpp"
#include "Solver.hpp"
#include <vector>
bool BFS(std::vector< std::vector<int> > &adj, int src, int dest, int mazeWidth, int mazeHeight, std::vector<int> &shortestPath, std::list<int> &queue, int *prev, bool *bfs_visited, std::vector<int> &bfs_show)
{
if (!queue.empty())
{
int u = queue.front();
queue.pop_front();
for (int i = 0; i < adj[u].size(); i++) {
if (bfs_visited[adj[u][i]] == false) {
/*render children to the screen*/
bfs_show.push_back(adj[u][i]);
/*end of render children*/
bfs_visited[adj[u][i]] = true;
prev[adj[u][i]] = u;
queue.push_back(adj[u][i]);
// We stop BFS when we find
// destination.
if (adj[u][i] == dest)
{
//std::cout << "FOUND" << std::endl;
int crawl = dest;
shortestPath.push_back(crawl);
while (prev[crawl] != src) {
//std::cout << "crawl: " << crawl << std::endl;
shortestPath.push_back(prev[crawl]);
crawl = prev[crawl];
}
//std::cout << shortestPath.size() << std::endl;
return true;
}
}
}
}
return false;
}