forked from justinhj/astar-algorithm-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathastar_demo.cpp
More file actions
executable file
·72 lines (54 loc) · 2.3 KB
/
astar_demo.cpp
File metadata and controls
executable file
·72 lines (54 loc) · 2.3 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
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
#include "stlastar.h" // See header for copyright and usage information
#include <iostream>
#include <stdio.h>
#include <Astar.h>
/******************* NOTES ON THE INPUT MAP **************************
Each element contains an integer from 0 to 5 which indicates the cost
of travel across the terrain. Zero means the least possible difficulty
in travelling (think ice rink if you can skate) whilst 5 represents the
most difficult. 9 indicates that we cannot pass.
**************************************************************************/
int aMap[] = {
// 0 2 4 6 8 10 12 14 16 18
// 1 3 5 7 9 11 13 15 17 19
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 00
1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,1, // 01
1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 02
1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 03
1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1, // 04
1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1, // 05
1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1, // 06
1,9,9,9,9,9,9,9,9,1,1,1,9,9,9,9,9,9,9,1, // 07
1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1, // 08
1,9,1,9,9,9,9,9,9,9,1,1,9,9,9,9,9,9,9,1, // 09
1,9,1,1,1,1,9,1,1,9,1,1,1,1,1,1,1,1,1,1, // 10
1,9,9,9,9,9,1,9,1,9,1,9,9,9,9,9,1,1,1,1, // 11
1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 12
1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 13
1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1, // 14
1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1, // 15
1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1, // 16
1,1,9,9,9,9,9,9,9,1,1,1,9,9,9,1,9,9,9,9, // 17
1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1, // 18
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 19
};
int main( int argc, char *argv[] )
{
std::vector<int> access_map(aMap, aMap + sizeof(aMap)/sizeof(int));
std::vector<int> solutionPath;
Astar myAstar(access_map, 20, 20);
//First run, printing solution using the Astar method
myAstar.run(43,380);
cout << "[Using class method] ";
myAstar.printSolution();
cout << endl;
//Second run, printing solution by getting the path
myAstar.run(380,43);
solutionPath = myAstar.path;
cout << "[Getting Path] Path from 380 to 43:" << endl;
for(int i=0; i<solutionPath.size();i++){
cout << " " << solutionPath.at(i);
}
cout << endl;
return 0;
}