aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzedarider <ymherklotz@gmail.com>2016-12-11 00:11:00 +0000
committerzedarider <ymherklotz@gmail.com>2016-12-11 00:11:00 +0000
commit26d86a9b1d18fdd5d5b925c08d83c8dc12bbfbac (patch)
treeba8a61ef8586e77afda1d6d2e893b460f7a75270
parent6cd142c799997346410c39bda2796b0942fbe2fa (diff)
downloadA-star-algorithm-26d86a9b1d18fdd5d5b925c08d83c8dc12bbfbac.tar.gz
A-star-algorithm-26d86a9b1d18fdd5d5b925c08d83c8dc12bbfbac.zip
adding closest working version
-rwxr-xr-xbin/mainbin417504 -> 417472 bytes
-rw-r--r--include/priority_queue.hpp3
-rw-r--r--src/astar.cpp4
-rw-r--r--src/main.cpp18
4 files changed, 13 insertions, 12 deletions
diff --git a/bin/main b/bin/main
index d261a1d..781ce54 100755
--- a/bin/main
+++ b/bin/main
Binary files differ
diff --git a/include/priority_queue.hpp b/include/priority_queue.hpp
index e7995e3..794638f 100644
--- a/include/priority_queue.hpp
+++ b/include/priority_queue.hpp
@@ -85,7 +85,8 @@ T PriorityQueue<T>::pop() {
else if(size == capacity / 2)
resize_queue(0.5);
- return remove_queue(0);
+ T tmp = remove_queue(0);
+ return tmp;
}
template<typename T>
diff --git a/src/astar.cpp b/src/astar.cpp
index c00b938..5374bea 100644
--- a/src/astar.cpp
+++ b/src/astar.cpp
@@ -29,8 +29,7 @@ bool AStar::start_algorithm(int *curr_graph, const unsigned int& width, const un
graph_height = height;
graph = curr_graph;
- std::vector<Node> tmp;
- closed_set = tmp;
+ closed_set.clear();
open_set.clear();
for(unsigned int i = 0; i < graph_width * graph_height; ++i)
@@ -38,6 +37,7 @@ bool AStar::start_algorithm(int *curr_graph, const unsigned int& width, const un
start_node.x = i % graph_width;
start_node.y = i / graph_width;
start_node.g_score = 0;
+ start_node.previous_node = NULL;
calc_heuristic(start_node);
calc_f(start_node);
} else if(graph[i] == 2) {
diff --git a/src/main.cpp b/src/main.cpp
index 4434e72..9031e14 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,13 +29,13 @@ int main(int argc, char *argv[]) {
// set the constants int the file that define the grid to be displayed.
// for the mac
- //const int tile_size = 21;
- //const int rows = 41;
- //const int cols = 34;
+ const int tile_size = 21;
+ const int rows = 41;
+ const int cols = 34;
- const int tile_size = 25;
- const int rows = 50;
- const int cols = 100;
+ // const int tile_size = 25;
+ // const int rows = 50;
+ // const int cols = 100;
// print out that information.
cout << "tile size: " << tile_size << "px, rows: " << rows << ", cols: " << cols << endl;
@@ -47,8 +47,8 @@ int main(int argc, char *argv[]) {
for(int i = 0; i < cols * rows; ++i)
tiles[i] = 0;
- tiles[210] = 3;
- tiles[4029] = 2;
+ tiles[74] = 3;
+ tiles[41 * 34 - 85] = 2;
// create a tile map that will be used to display the array.
TileMap map;
@@ -65,7 +65,7 @@ int main(int argc, char *argv[]) {
if(event.type == sf::Event::Closed)
window.close();
- // check if mouse buttons are pressed.
+ // check if mouse buttons are prgetSizeessed.
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
// get the position of the mouse.
sf::Vector2i mouse = sf::Mouse::getPosition(window);