diff options
author | ymherklotz <ymherklotz@gmail.com> | 2016-12-10 00:02:43 +0000 |
---|---|---|
committer | ymherklotz <ymherklotz@gmail.com> | 2016-12-10 00:02:43 +0000 |
commit | 963a8d2b5f80a111514dc6eaa56d6b637ee783e1 (patch) | |
tree | 590efd6021b2c49b3afc13e08069a5be1488a1a8 /src | |
parent | 879f058f89cd51e87c741025df1b13146e3aef1b (diff) | |
download | A-star-algorithm-963a8d2b5f80a111514dc6eaa56d6b637ee783e1.tar.gz A-star-algorithm-963a8d2b5f80a111514dc6eaa56d6b637ee783e1.zip |
starting astar algorithm
Diffstat (limited to 'src')
-rw-r--r-- | src/astar.cpp | 25 | ||||
-rw-r--r-- | src/main.cpp | 24 | ||||
-rw-r--r-- | src/node.cpp | 20 |
3 files changed, 44 insertions, 25 deletions
diff --git a/src/astar.cpp b/src/astar.cpp index b533130..b556d76 100644 --- a/src/astar.cpp +++ b/src/astar.cpp @@ -1,4 +1,27 @@ #include "astar.hpp" -AStar::AStar() { +AStar::AStar(int *curr_graph, const unsigned int& width, const unsigned int& height) : graph(curr_graph), graph_width(width), graph_height(height) { + set_start_end(); + open_set.push(start_node); +} + +void AStar::set_start_end() { + for(unsigned int i = 0; i < graph_width * graph_height; ++i) + if(graph[i] == 3) { + start_node.x = i % graph_width; + start_node.y = i / graph_width; + start_node.g_score = 0; + } else if(graph[i] == 2) { + end_node.x = i % graph_width; + end_node.y = i / graph_width; + end_node.h_score = 0; + } +} + +Node AStar::get_neighbour(const Node& n_in, const int& neighbour_num) { + if(neighbour_num == 0) { + } +} + +void AStar::calc_heuristic(Node& n) { } diff --git a/src/main.cpp b/src/main.cpp index 2e51f2f..494ff43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,29 +16,5 @@ using namespace std; int main(int argc, char *argv[]) { - PriorityQueue<Node> pq; - - Node n, n2, n3, n4, n5, n6; - n.set_f(65); - n2.set_f(2); - n3.set_f(6); - n4.set_f(34); - n5.set_f(75); - n6.set_f(2); - - pq.push(n); - pq.push(n2); - pq.push(n3); - pq.push(n4); - pq.push(n5); - pq.push(n6); - - cout << "First node in queue: " << pq.pop() << endl; - cout << "Second node in queue: " << pq.pop() << endl; - cout << "Third node in queue: " << pq.pop() << endl; - cout << "Fourth node in queue: " << pq.pop() << endl; - cout << "Fifth node in queue: " << pq.pop() << endl; - cout << "Sixth node in queue: " << pq.pop() << endl; - return 0; } diff --git a/src/node.cpp b/src/node.cpp index c10aa1b..9273376 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -3,6 +3,26 @@ Node::Node() : previous_node(NULL), f_score(-1), g_score(0), h_score(-1), x(0), y(0) { } +void Node::set_x(int x_in) { + x = x_in; +} + +void Node::set_y(int y_in) { + y = y_in; +} + +void Node::set_h_score(int h) { + h_score = h; +} + +void Node::set_g_score(int g) { + g_score = g; +} + +void Node::compute_f() { + f_score = g_score + h_score; +} + bool operator<(const Node& n1, const Node& n2) { if(n1.f_score == n2.f_score) return n1.h_score < n2.h_score; |