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
| #include <iostream> #include<vector> #include<windows.h> #include"Draw.h" #include"DFS.h" #include"BFS.h" #include"Search.h" using namespace std; vector<vector<int>> map = { {0,0,1,0,1,0,1}, {1,0,0,0,0,0,1}, {1,0,1,1,1,0,0}, {1,0,0,0,1,1,1}, {0,0,1,0,0,0,1}, {1,0,1,0,1,0,0}, {1,0,1,1,1,0,1}, };
bool check(int x, int y) { if ((y < 0 || x<0) || y >= map.size() ||x>=map[y].size() || map[y][x] == 1) { return false; } return true; }
void test() { Draw draw(600, map); draw.updata(); }
void test1() { DFS dfs(check); Draw draw(600, map); Pos start{ 0,0 }; Pos end{ 1,6 }; draw.level[end.y][end.x] = Draw::end; draw.updata(); const auto& path = dfs.recursive(start,end); for (const auto& e : path) { draw.level[e.y][e.x] = Draw::visit; draw.updata(); Sleep(500); } }
void test2() { BFS bfs(check); Draw draw(600, map); Pos start{ 1,1 }; Pos end{ 3,0 }; draw.level[end.y][end.x] = Draw::end; draw.updata(); const auto& path = bfs.queue(start, end); for (const auto& e : path) { draw.level[e.y][e.x] = Draw::visit; draw.updata(); Sleep(500); }
} int main() { system("pause"); return 0; }
|