Your for
loops currently iterate over all 9 possible actions (moving in the 8 possible directions and staying put).
Add an if
statement inside your second for
loop that will ignore the moves that you don't want. Something like this:
for (int xd=-1;xd<=1;xd++)
{
for (int yd=-1;yd<=1;yd++)
{
// you want only up, down, left, or right moves
// those are if one of xd or yd == 0
if ((xd != 0 && yd != 0) || (xd == 0 && yd == 0))
continue;
if (Map.getMap (x+xd,y+yd) !=-1)
{
Node n = new Node (this,this._goalNode ,Map.getMap (x+xd,y+yd) ,x+xd,y+yd);
if (!n.isMatch (this.parentNode) && !n.isMatch (this))
successors.Add (n);
}
}
}