17 #define DEBUG_LIST_LENGTHS_ONLY 0 24 static uint8_t*
_map = NULL;
27 uint8_t
GetMap(
unsigned int x,
unsigned int y )
78 cout <<
"Node position : (" << x <<
", " << y <<
")" << endl;
86 float xd = fabs(
float(((
float)x - (
float)nodeGoal.
x)));
87 float yd = fabs(
float(((
float)y - (
float)nodeGoal.
y)));
95 if( (x == nodeGoal.
x) &&
117 parent_x = parent_node->
x;
118 parent_y = parent_node->
y;
128 if( (
GetMap( ix-1, iy ) < 9u)
129 && !((parent_x == ix-1) && (parent_y == iy))
136 if( (
GetMap( ix, iy-1 ) < 9u)
137 && !((parent_x == ix) && (parent_y == iy-1))
144 if( (
GetMap( ix+1, iy ) < 9u)
145 && !((parent_x == ix+1) && (parent_y == iy))
153 if( (
GetMap( ix, iy+1 ) < 9u)
154 && !((parent_x == ix) && (parent_y == iy+1))
170 return (
float)
GetMap( x, y );
185 std::vector<point_t>& path )
204 unsigned int SearchCount = 0;
206 const unsigned int NumSearches = 1;
208 bool path_found =
false;
210 while(SearchCount < NumSearches)
215 nodeStart.
x = start.
x;
216 nodeStart.
y = start.
y;
227 unsigned int SearchState;
228 unsigned int SearchSteps = 0;
238 cout <<
"Steps:" << SearchSteps <<
"\n";
247 #if !DEBUG_LIST_LENGTHS_ONLY 254 cout <<
"Open list has " << len <<
" nodes\n";
263 #if !DEBUG_LIST_LENGTHS_ONLY 269 cout <<
"Closed list has " << len <<
" nodes\n";
282 cout <<
"Displaying solution\n";
288 path.push_back(
point_t( node->
x, node->
y ) );
301 path.push_back(
point_t( node->
x, node->
y ) );
317 cout <<
"Search terminated. Did not find goal state\n";
bool GetSuccessors(AStarSearch< MapSearchNode > *astarsearch, MapSearchNode *parent_node)
bool astar(uint8_t *map, uint32_t width, uint32_t height, const point_t start, const point_t goal, std::vector< point_t > &path)
UserState * GetOpenListStart()
bool IsSameState(MapSearchNode &rhs)
UserState * GetOpenListNext()
UserState * GetClosedListStart()
MapSearchNode(unsigned int px, unsigned int py)
UserState * GetClosedListNext()
void SetStartAndGoalStates(UserState &Start, UserState &Goal)
float GetCost(MapSearchNode &successor)
static unsigned int _map_width
static unsigned int _map_height
unsigned int SearchStep()
bool AddSuccessor(UserState &State)
uint8_t GetMap(unsigned int x, unsigned int y)
float GoalDistanceEstimate(MapSearchNode &nodeGoal)
bool IsGoal(MapSearchNode &nodeGoal)
UserState * GetSolutionStart()
UserState * GetSolutionNext()