From 250a680cadd59e50c1128564cf62c75a2ffca608 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sat, 8 Jun 2019 17:08:15 +0200 Subject: [PATCH] Fixed target initialization still using sf::Vector2i Forgot to move manhattanDistance to .cpp --- src/Entity.cpp | 2 +- src/Utils.cpp | 7 +++++++ src/Utils.h | 7 +------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Entity.cpp b/src/Entity.cpp index df05975..f4ebf56 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -21,7 +21,7 @@ Entity::Entity(int x, int y, EntityType type, sf::Texture* texture, int width, i currentState = State::Idle; nextState = State::Idle; - target = sf::Vector2i(shape.getPosition()); + target = pro_maat::GridPos(x,y); nextTarget = target; } diff --git a/src/Utils.cpp b/src/Utils.cpp index 4c75c2f..153f214 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -36,4 +36,11 @@ namespace pro_maat window.display(); } } + + float manhattanDistance(pro_maat::GridPos leftHandSide, pro_maat::GridPos rightHandSide) + { + // The *0.01 helps with breaking ties and minimizing exploration + // As per http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#breaking-ties + return (std::abs(rightHandSide.first-leftHandSide.first)+std::abs(rightHandSide.second-leftHandSide.second))*1.01; + } } \ No newline at end of file diff --git a/src/Utils.h b/src/Utils.h index 431ed1a..f6331c6 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -23,12 +23,7 @@ static constexpr char fontFolder[] = "resources/"; void errorWindow(const std::string& error); // Good heuristic on 4-way grids -double manhattanDistance(pro_maat::GridPos leftHandSide, pro_maat::GridPos rightHandSide) -{ - // The *0.01 helps with breaking ties and minimizing exploration - // As per http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#breaking-ties - return (std::abs(rightHandSide.first-leftHandSide.first)+std::abs(rightHandSide.second-leftHandSide.second))*1.01; -} +float manhattanDistance(pro_maat::GridPos leftHandSide, pro_maat::GridPos rightHandSide); }