Skip to content

Instantly share code, notes, and snippets.

@Jalalx
Created February 8, 2014 14:04
Show Gist options
  • Save Jalalx/8884238 to your computer and use it in GitHub Desktop.
Save Jalalx/8884238 to your computer and use it in GitHub Desktop.
class Node : IComparable<Node>
{
public int H
{
get
{
return Math.Abs(X - TargetNode.Position.X) +
Math.Abs(Y - TargetNode.Position.Y);
}
}
public int G
{
get
{
if(ParentNode == null)
return 0;
return ParentNode.G + 1;
}
}
public int F
{
get { return G + H; }
}
public int X
{
get { return ((int) Position.X); }
}
public int Y
{
get { return ((int)Position.Y); }
}
public Node ParentNode;
public Node TargetNode;
public Node (int x, int y)
{
Position = new Vector2(x, y);
}
public Node(int x, int y, Node parentNode)
{
ParentNode = parentNode;
Position = new Vector2(x, y);
}
public int CompareTo(Node node)
{
if(F > node.F)
return 1;
if(F < node.F)
return -1;
return 0;
}
public bool Equals(Node node)
{
if (X == node.X && Y == node.Y)
return true;
return false;
}
public static bool operator ==(Node n1, Node n2)
{
return n1.Equals(n2);
}
public static bool operator !=(Node n1, Node n2)
{
return !n1.Equals(n2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment