-
Notifications
You must be signed in to change notification settings - Fork 0
/
astartest.cc
113 lines (88 loc) · 2.99 KB
/
astartest.cc
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
// LICENSE: GPLv3.
//
// Code written by haley clark in 2011.
//
// This code shows how to use the implementation of the A* algorithm.
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#define BRDSIZ 40
bool SEEDED = false;
std::string thepath[BRDSIZ + 1][BRDSIZ + 1];
#include "Utilities.h"
int myrand(void) { // Random number generator: 0-BRDSIZ range.
if(!SEEDED) {
unsigned int iseed = (unsigned int)::time(NULL);
::srand(iseed);
SEEDED = true;
}
return ::rand() % BRDSIZ;
}
int main() {
std::vector<std::vector<int>> final_path;
std::vector<int> beginning;
beginning.push_back(myrand()); // x
beginning.push_back(myrand()); // y
// beginning.push_back(0); //x
// beginning.push_back(52); //y
std::vector<int> end;
end.push_back(myrand()); // x
end.push_back(myrand()); // y
// end.push_back(45); //x
// end.push_back(62); //y
while(beginning == end) {
end.clear();
end.push_back(myrand()); // x
end.push_back(myrand()); // y
}
// Colour the board unused.
for(unsigned int i = 0; i <= (BRDSIZ); ++i)
for(unsigned int j = 0; j <= (BRDSIZ); ++j) {
thepath[i][j] = "░";
}
final_path = AStar(beginning, end);
// final_path = _AStar_FULL<double, Myloc_Heuristic_Func_Type>(beginning, end, NULL);
std::cout << "Start node: " << beginning[0] << " " << beginning[1] << std::endl;
std::cout << "Target node: " << end[0] << " " << end[1] << std::endl;
// Plot the path with filled circles.
for(unsigned int i = 0; i < final_path.size(); ++i) {
size_t x = final_path[i][0];
size_t y = final_path[i][1];
thepath[x][y] = "◉";
}
// Fill the endpoints with special glyphs.
thepath[end[0]][end[1]] = "◬";
thepath[beginning[0]][beginning[1]] = "◦";
// Draw the board.
for(int j = (BRDSIZ); j >= 0; --j) {
std::cout << std::endl;
std::cout.width(2);
std::cout << (j);
std::cout.width(1);
std::cout << " ";
for(unsigned int i = 0; i <= BRDSIZ; ++i) {
std::cout << thepath[i][j] << " ";
}
}
std::cout << std::endl << std::endl << " ";
for(unsigned int i = 0; i <= BRDSIZ; ++i) {
if(static_cast<int>(i / 10) == 0) {
std::cout << " ";
} else {
std::cout << static_cast<int>(i / 10) << " ";
}
}
std::cout << std::endl << " ";
for(unsigned int i = 0; i <= BRDSIZ; ++i) std::cout << i % 10 << " ";
std::cout << std::endl;
std::cout << "Key:" << std::endl;
std::cout << " ░ -- Unvisited node (it was visitable.)" << std::endl;
std::cout << " █ -- Blocked node (it was not visitable.)" << std::endl;
std::cout << " ◉ -- Trajectory node." << std::endl;
std::cout << " ◬ -- Target node." << std::endl;
std::cout << " ◦ -- Start node." << std::endl;
return 0;
}