AdventOfCode/Advent Of Code Library/Shared/A-Star/AStarNode.cs
2023-11-27 21:50:58 +01:00

41 lines
999 B
C#

namespace AdventOfCodeLibrary.Shared.A_Star
{
public class AStarNode : Node
{
/// <summary>
/// Distance from start node
/// </summary>
public int GCost { get; set; } = 0;
/// <summary>
/// Distance from end node
/// </summary>
public int HCost { get; set; }
/// <summary>
/// Total cost (G + F)
/// </summary>
public int FCost => GCost + HCost;
public bool? IsClosed { get; private set; } = null;
public AStarNode? ParentNode { get; set; }
public AStarNode(Node position) : base(position)
{ }
public AStarNode(int x, int y, char value) : base(x, y, value)
{ }
public void OpenNode() => IsClosed = false;
public void CloseNode() => IsClosed = true;
public bool CanMoveTo(AStarNode target)
{
int diff = target.Integer - Integer; ;
return diff == 0 || diff == 1;
}
}
}