From 61e0e87e90101aa565b088687785b6c73b9c5c58 Mon Sep 17 00:00:00 2001 From: zedarider Date: Wed, 21 Dec 2016 15:18:29 +0000 Subject: optimised and using array instead of vector --- bin/main | Bin 356696 -> 356696 bytes src/astar.cpp | 23 +++++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bin/main b/bin/main index 449e64f..87f8790 100755 Binary files a/bin/main and b/bin/main differ diff --git a/src/astar.cpp b/src/astar.cpp index df2115b..21c518d 100644 --- a/src/astar.cpp +++ b/src/astar.cpp @@ -49,7 +49,11 @@ bool AStar::start_algorithm(int *curr_graph, const unsigned int& width, const un bool AStar::start_algorithm() { open_set.clear(); - find_start_end(); + if(!find_start_end()) { + throw "Couldn't find start or end"; + return false; + } + reset_closed_set(); open_set.push(start_node); while(open_set.first() != end_node) { Node current = open_set.pop(); @@ -100,7 +104,6 @@ bool AStar::find_start_end() { } else if(graph[i] == 2) { end_node.index = i; } - open_set.push(start_node); Node n; return !(start_node == n || end_node == n); } @@ -109,28 +112,28 @@ Node AStar::get_neighbour(Node& n_in, const int& neighbour_num) { Node n; if(neighbour_num == 0 && n_in.index / graph_width > 0) { - n.index -= graph_width; + n.index = n_in.index - graph_width; path_length = PATHLENGTH; } else if(neighbour_num == 1 && n_in.index % graph_width < graph_width - 1) { - n.index += 1; + n.index = n_in.index + 1; path_length = PATHLENGTH; } else if(neighbour_num == 2 && n_in.index / graph_width < graph_height - 1) { - n.index += graph_width; + n.index = n_in.index + graph_width; path_length = PATHLENGTH; } else if(neighbour_num == 3 && n_in.index % graph_width > 0) { - n.index -= 1; + n.index = n_in.index - 1; path_length = PATHLENGTH; } else if(neighbour_num == 4 && n_in.index / graph_width > 0 && n_in.index % graph_width < graph_height - 1) { - n.index -= graph_width + 1; + n.index = n_in.index - graph_width + 1; path_length = DIAGLENGTH; } else if(neighbour_num == 5 && n_in.index / graph_width < graph_height - 1 && n_in.index % graph_width < graph_width - 1) { - n.index += graph_width + 1; + n.index = n_in.index + graph_width + 1; path_length = DIAGLENGTH; } else if(neighbour_num == 6 && n_in.index / graph_width < graph_height - 1 && n_in.index % graph_width > 0) { - n.index -= graph_width - 1; + n.index = n_in.index - graph_width - 1; path_length = DIAGLENGTH; } else if(neighbour_num == 7 && n_in.index / graph_width > 0 && n_in.index % graph_width > 0) { - n.index -= graph_width - 1; + n.index = n_in.index + graph_width - 1; path_length = DIAGLENGTH; } -- cgit