A* Pseudocode: Given: cell *M[ROWS][COLS] as representing map M[i][j]->terrain is either OPEN or WATER M[i][j]->prev is initially NULL, and should provide best path back to starting point after Astar is called // find reverse path from sy,sx to ty,tx void Astar(int sy, int sx, int ty, int tx) { cell * current; // the current node to expand create interior and frontier structures. insert M[sy][sx], which is the start node into the frontier set boolean var stop to false; this controls when loop should exit. while (!stop and fontier is not empty) { find cell on frontier with lowest cost - call this cell current delete current from fontier and move it to interior. for each neighbor north south east west of current: add neighbor to frontier (and call calccost) if it's not already in either frontier or interior, and if it's OPEN (water is impassable). For example, if current have coordiates i, j, then the NORTH neighbor will be at M[i-1][j], so you'll have code that looks like: if ( i>0 && M[i-1][j]->terrain is OPEN && M[i-1][j] is not on interior && M[i-1][j] is not on frontier ) { call calccost to set cost value (if cost is a field of cell) on M[i-1][j]. add M[i-1][j] to frontier. set M[i-1][j]->prev to current to record path followed if i-1==ty and j==tx, then target found, so set stop to true. } } // while } // pseudocode for calc cost: { follow prev pointer from current node until it's null, count the number of links. This is the cost back to the origin. Compute the straight-line distance to ty,tx, and add this to the cost. } ////////////// Added To represent the cost, I recommend BOTH writing a calccost function AND add another variable "cost" to the cell class. The calccost function should set the cost variable when called. Otherwise, you'll have problems defining the comparator class.