aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorymherklotz <ymherklotz@gmail.com>2016-12-12 21:25:17 +0000
committerymherklotz <ymherklotz@gmail.com>2016-12-12 21:25:17 +0000
commit34c24c08e646113fa6a020099c7222b2059ffd38 (patch)
treef2b25e68f8cb31ac81f15db05875d1c520ccb147
parent0c1f72762e9c0fbc03bb07db2219cff3b4427f3e (diff)
downloadA-star-algorithm-34c24c08e646113fa6a020099c7222b2059ffd38.tar.gz
A-star-algorithm-34c24c08e646113fa6a020099c7222b2059ffd38.zip
bug detected when pathing backwards and down
-rwxr-xr-xbin/mainbin416200 -> 416128 bytes
-rw-r--r--include/astar.hpp2
-rw-r--r--include/node.hpp2
-rw-r--r--src/astar.cpp8
4 files changed, 4 insertions, 8 deletions
diff --git a/bin/main b/bin/main
index 9d9d0a3..a43b3ff 100755
--- a/bin/main
+++ b/bin/main
Binary files differ
diff --git a/include/astar.hpp b/include/astar.hpp
index 321431c..a8225f3 100644
--- a/include/astar.hpp
+++ b/include/astar.hpp
@@ -29,8 +29,6 @@ private:
int graph_height;
int path_length;
- int count;
-
Node start_node, end_node;
bool start_algorithm();
diff --git a/include/node.hpp b/include/node.hpp
index 5e29d81..f126fc4 100644
--- a/include/node.hpp
+++ b/include/node.hpp
@@ -31,7 +31,7 @@ private:
// path length to get to that node.
int g_score;
// heuristic length to destination.
- double h_score;
+ int h_score;
// the x and y coordinates of the node in the grid
int x, y;
diff --git a/src/astar.cpp b/src/astar.cpp
index be36ab8..a8fa970 100644
--- a/src/astar.cpp
+++ b/src/astar.cpp
@@ -2,7 +2,7 @@
#include <cmath>
-AStar::AStar() : graph(NULL), graph_width(0), graph_height(0), path_length(10), count(0) {
+AStar::AStar() : graph(NULL), graph_width(0), graph_height(0), path_length(10) {
}
AStar::AStar(int *curr_graph, const unsigned int& width, const unsigned int& height) : graph(curr_graph), graph_width(width), graph_height(height), path_length(1) {
@@ -66,6 +66,7 @@ bool AStar::start_algorithm() {
remove_from_vec(n);
if(!open_set.check_item(n) && !check_item_vec(n)) {
n.g_score = cost;
+ calc_heuristic(n);
calc_f(n);
n.x_prev = current.x;
n.y_prev = current.y;
@@ -122,14 +123,11 @@ Node AStar::get_neighbour(Node& n_in, const int& neighbour_num) {
path_length = 14;
}
- calc_heuristic(n);
-
return n;
}
void AStar::calc_heuristic(Node& n) {
- n.h_score = sqrt(pow(10 * (end_node.x - n.x), 2) + pow(10 * (end_node.y - n.y), 2)) * (1 + 0.01 * count);
- ++count;
+ n.h_score = pow(10 * (end_node.x - n.x), 2) + pow(10 * (end_node.y - n.y), 2);
}
void AStar::calc_f(Node& n) {