[Add] Working some more on AStar pathfinding. This is going to get messy.
This commit is contained in:
parent
816ea51c86
commit
86c102f3d2
@ -1 +1,23 @@
|
|||||||
#include "Pathfinding.h"
|
#include "Pathfinding.h"
|
||||||
|
|
||||||
|
template<typename UserState>
|
||||||
|
AStarSearch<UserState>::AStarSearch(void) :
|
||||||
|
_state(SEARCH_STATE_NOT_INITIALISED),
|
||||||
|
_currentSolutionNode(NULL),
|
||||||
|
_allocateNodeCount(0),
|
||||||
|
_cancelRequest(false) {}
|
||||||
|
|
||||||
|
template<typename UserState>
|
||||||
|
AStarSearch<UserState>::~AStarSearch(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename UserState>
|
||||||
|
void AStarSearch<UserState>::SetStartAndGoalStates(UserState& start, UserState& goal) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename UserState>
|
||||||
|
unsigned int AStarSearch<UserState>::SearchStep(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// A node representing a possible state in the search.
|
// A node representing a possible state in the search.
|
||||||
|
public:
|
||||||
class Node {
|
class Node {
|
||||||
public:
|
public:
|
||||||
// Keep a record of successor nodes.
|
// Keep a record of successor nodes.
|
||||||
@ -51,6 +52,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
AStarSearch(void);
|
AStarSearch(void);
|
||||||
|
~AStarSearch(void);
|
||||||
|
|
||||||
int GetState(void) { return _state; }
|
int GetState(void) { return _state; }
|
||||||
|
|
||||||
@ -103,7 +105,41 @@ public:
|
|||||||
int GetStepCount(void) {return _steps; }
|
int GetStepCount(void) {return _steps; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _state;
|
// Called when a search fails or is cancelled to free up all unused memory.
|
||||||
|
void FreeAllNodes(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called when the search ends. A lot of nodes may
|
||||||
|
* be created that are still present when the search
|
||||||
|
* ends. They will be deleted with this method.
|
||||||
|
*/
|
||||||
|
void FreeUnusedNodes(void);
|
||||||
|
|
||||||
|
// Data.
|
||||||
|
private:
|
||||||
|
// Heap.
|
||||||
|
vector<Node*> _openList;
|
||||||
|
vector<Node*> _closedList;
|
||||||
|
vector<Node*> _successors;
|
||||||
|
|
||||||
|
// State.
|
||||||
|
unsigned int _state;
|
||||||
|
|
||||||
|
// Count steps.
|
||||||
|
int _steps;
|
||||||
|
|
||||||
|
// Start/Goal state pointers.
|
||||||
|
Node* _start;
|
||||||
|
Node* _goal;
|
||||||
|
|
||||||
|
Node* _currentSolutionNode;
|
||||||
|
|
||||||
|
// Debug
|
||||||
|
typename vector<Node*>::iterator iterDbgOpen;
|
||||||
|
typename vector<Node*>::iterator iterDbgClosed;
|
||||||
|
|
||||||
|
// Count memory allocations and free.
|
||||||
|
int _allocateNodeCount;
|
||||||
|
|
||||||
bool _cancelRequest;
|
bool _cancelRequest;
|
||||||
int _steps;
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user