I'm trying to implement A*. Basically it works as long as there is no walls. Kind of defeats the purpose, eh? Some pictures:

This works as it should. (I think?)

This doesn't. Green dot = starting node Red dot = goal node Blue dots are nodes on the closed list, and white = openlist When it gets to the wall, the current nodes F score is lower than any on the open list. So it's just an endless loop. Not sure why this happens. My loop:
do
{
iter++;
if( iter > 200 )
return;
for( int i = 0; i < openlist.size(); i++ )
{
node n = openlist.get( i );
if( n.F() <= currentnode.F() )
{
currentnode = n;
}
}
openlist.remove( currentnode );
closedlist.push( currentnode );
if( isgoal( currentnode, e ) )
return;
expand( expansions, currentnode, e );
for( int i = 0; i < expansions.size(); i++ )
{
node n = expansions.get( i );
int newg = currentnode.G + getgcost( currentnode, n );
if( !walkable( n.x, n.y ) )
continue;
if( isgoal( n, e ) )
return;
if( closedlist.contains( n ) )
continue;
if( !openlist.contains( n ) )
{
n.G = newg;
n.parent = ¤tnode
openlist.push( n );
continue;
}
else
{
if( n.G < newg )
{
openlist.remove( n );
n.G = newg;
n.parent = ¤tnode
openlist.push( n );
continue;
}
n.G = newg;
n.parent = ¤tnode
openlist.push( n );
}
}
}
while( !openlist.empty() );
}
Thanks for any help!