Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/8puzzle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#include <ctype.h>

using namespace std;

// Configuration

#define NUM_TIMES_TO_RUN_SEARCH 1
Expand All @@ -27,6 +25,8 @@ using namespace std;
// AStar search class
#include "stlastar.h" // See header for copyright and usage information

using namespace std;

// Global data

#define BOARD_WIDTH (3)
Expand Down
4 changes: 2 additions & 2 deletions cpp/findpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <stdio.h>
#include <math.h>

using namespace std;

#include "stlastar.h" // See header for copyright and usage information

using namespace std;

#define DEBUG_LISTS 0
#define DEBUG_LIST_LENGTHS_ONLY 0

Expand Down
4 changes: 2 additions & 2 deletions cpp/min_path_to_Bucharest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include <vector>
#include <stdio.h>

using namespace std;

#include "stlastar.h"

using namespace std;

#define DEBUG_LISTS 0
#define DEBUG_LIST_LENGTHS_ONLY 0

Expand Down
28 changes: 14 additions & 14 deletions cpp/stlastar.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ template <class UserState> class AStarSearch

bool operator==(const Node& otherNode) const
{
return this->m_UserState.IsSameState(otherNode->m_UserState);
return this->m_UserState.IsSameState(otherNode.m_UserState);
}

UserState m_UserState;
Expand Down Expand Up @@ -268,7 +268,7 @@ template <class UserState> class AStarSearch
if( !ret )
{

typename vector< Node * >::iterator successor;
typename std::vector< Node * >::iterator successor;

// free the nodes that may previously have been added
for( successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
Expand All @@ -287,7 +287,7 @@ template <class UserState> class AStarSearch
}

// Now handle each successor to the current node ...
for( typename vector< Node * >::iterator successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
for( typename std::vector< Node * >::iterator successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
{
// The g value for this successor ...
float newg = n->g + n->m_UserState.GetCost( (*successor)->m_UserState );
Expand All @@ -298,7 +298,7 @@ template <class UserState> class AStarSearch

// First linear search of open list to find node

typename vector< Node * >::iterator openlist_result;
typename std::vector< Node * >::iterator openlist_result;

for( openlist_result = m_OpenList.begin(); openlist_result != m_OpenList.end(); openlist_result ++ )
{
Expand All @@ -321,7 +321,7 @@ template <class UserState> class AStarSearch
continue;
}
}
typename unordered_set<Node*, NodeHash, NodeEqual>::iterator closedlist_result;
typename std::unordered_set<Node*, NodeHash, NodeEqual>::iterator closedlist_result;

closedlist_result = m_ClosedList.find(*successor);

Expand Down Expand Up @@ -664,7 +664,7 @@ template <class UserState> class AStarSearch
void FreeAllNodes()
{
// iterate open list and delete all nodes
typename vector< Node * >::iterator iterOpen = m_OpenList.begin();
typename std::vector< Node * >::iterator iterOpen = m_OpenList.begin();

while( iterOpen != m_OpenList.end() )
{
Expand All @@ -677,7 +677,7 @@ template <class UserState> class AStarSearch
m_OpenList.clear();

// iterate closed list and delete unused nodes
typename unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;
typename std::unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;

for( iterClosed = m_ClosedList.begin(); iterClosed != m_ClosedList.end(); iterClosed ++ )
{
Expand All @@ -699,7 +699,7 @@ template <class UserState> class AStarSearch
void FreeUnusedNodes()
{
// iterate open list and delete unused nodes
typename vector< Node * >::iterator iterOpen = m_OpenList.begin();
typename std::vector< Node * >::iterator iterOpen = m_OpenList.begin();

while( iterOpen != m_OpenList.end() )
{
Expand All @@ -718,7 +718,7 @@ template <class UserState> class AStarSearch
m_OpenList.clear();

// iterate closed list and delete unused nodes
typename unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;
typename std::unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;

for( iterClosed = m_ClosedList.begin(); iterClosed != m_ClosedList.end(); iterClosed ++ )
{
Expand Down Expand Up @@ -773,7 +773,7 @@ template <class UserState> class AStarSearch
private: // data

// Heap (simple vector but used as a heap, cf. Steve Rabin's game gems article)
vector< Node *> m_OpenList;
std::vector< Node *> m_OpenList;

// Closed is an unordered_set
struct NodeHash {
Expand All @@ -786,12 +786,12 @@ template <class UserState> class AStarSearch
return a->m_UserState.IsSameState(b->m_UserState);
}
};
unordered_set<Node*, NodeHash, NodeEqual> m_ClosedList;
std::unordered_set<Node*, NodeHash, NodeEqual> m_ClosedList;


// Successors is a vector filled out by the user each type successors to a node
// are generated
vector< Node * > m_Successors;
std::vector< Node * > m_Successors;

// State
unsigned int m_State;
Expand All @@ -812,8 +812,8 @@ template <class UserState> class AStarSearch

//Debug : need to keep these two iterators around
// for the user Dbg functions
typename vector< Node * >::iterator iterDbgOpen;
typename vector< Node * >::iterator iterDbgClosed;
typename std::vector< Node * >::iterator iterDbgOpen;
typename std::vector< Node * >::iterator iterDbgClosed;

// debugging : count memory allocation and free's
int m_AllocateNodeCount;
Expand Down
4 changes: 2 additions & 2 deletions cpp/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <stdlib.h>
#include <assert.h>

using namespace std;

#include "stlastar.h"

using namespace std;

const int MAP_WIDTH = 20;
const int MAP_HEIGHT = 20;

Expand Down