bleck, reverting

master
MitchellHansen 9 years ago
parent 56c4f158fc
commit 68aa5ac3e2

@ -5,6 +5,7 @@ Explorer::Explorer(Map* map_) {
color = sf::Color::Blue;
position = sf::Vector2i(10, 10);
map = map_;
pather = new Pather(map_);
}
@ -24,7 +25,7 @@ bool Explorer::move() {
// While there are moves for us to take
if (!movement_stack.empty()) {
bool valid = false; // If the next move is valid, collision
int x = movement_stack.top();
int x = movement_stack.front();
switch (x) {
@ -59,13 +60,13 @@ bool Explorer::move() {
std::cout << "Path blocked" << std::endl;
// Flush the moves list
while(!movement_stack.empty()) {
movement_stack.pop();
movement_stack.pop_front();
}
return false;
}
// If everything went well, pop and return true
movement_stack.pop();
movement_stack.pop_front();
return true;
}
else
@ -74,6 +75,6 @@ bool Explorer::move() {
// A*
bool Explorer::plan(sf::Vector2i destination_) {
movement_stack = pather->pathTo(position, destination_);
return true;
}

@ -2,6 +2,7 @@
#include <SFML/Graphics.hpp>
#include <stack>
#include "Map.h"
#include "Pather.h"
class Explorer {
public:
@ -13,8 +14,9 @@ private:
sf::Color color;
sf::Vector2i position;
Map* map;
Pather* pather;
std::stack<int> movement_stack;
std::deque<int> movement_stack;
bool move();
bool plan(sf::Vector2i destination_);
};

@ -100,6 +100,10 @@ Pather::Pather(Map* map_) {
map = map_;
}
Pather::Pather() {
}
Pather::~Pather() {
}
@ -107,7 +111,7 @@ sf::Vector2i Pather::getEndNodePosition() {
return end_node->xy;
}
std::vector<int> Pather::pathTo(sf::Vector2i start, sf::Vector2i end) {
std::deque<int> Pather::pathTo(sf::Vector2i start, sf::Vector2i end) {
// Clear the visited map for erroneous data
for (int i = 0; i < Map::CELLS_WIDTH; i++) {
@ -129,13 +133,13 @@ std::vector<int> Pather::pathTo(sf::Vector2i start, sf::Vector2i end) {
openList.emplace(start_node, 0);
early_exit = false;
//path_list = Loop();
path_list = loop();
return path_list;
}
std::vector<int> Pather::loop() {
std::deque<int> Pather::loop() {
while (!openList.empty() && !early_exit) {
// Early exit jankyness, need to change this
if (closedList.size() > 3000) {
@ -172,17 +176,17 @@ std::vector<int> Pather::loop() {
}
}
std::vector<int> return_path = returnPath();
std::deque<int> return_path = returnPath();
if (no_path || return_path.empty()) {
return std::vector<int>(0, 0);
std::cout << " no return path " << std::endl;
return return_path;
}
return return_path;
}
std::vector<int> Pather::returnPath() {
std::vector<int> path;
std::deque<int> Pather::returnPath() {
std::deque<int> path;
while (active_node != nullptr) {
path.push_back(active_node->cameFrom);

@ -29,6 +29,7 @@ private:
class Pather {
public:
Pather(Map* map_);
Pather();
~Pather();
Map* map;
@ -37,9 +38,9 @@ public:
std::unordered_map<node*, int> closedList;
int visitedMap[App::WINDOW_HEIGHT][App::WINDOW_WIDTH];
std::vector<int> pathTo(sf::Vector2i start, sf::Vector2i end);
std::vector<int> loop();
std::vector<int> returnPath();
std::deque<int> pathTo(sf::Vector2i start, sf::Vector2i end);
std::deque<int> loop();
std::deque<int> returnPath();
sf::Vector2i getEndNodePosition();
@ -51,7 +52,7 @@ public:
private:
std::vector<int> path_list;
std::deque<int> path_list;
node* end_node;
};

@ -1,6 +1,7 @@
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "App.h"
#include "Pather.h"
int main()
{

Loading…
Cancel
Save