private static AStarPathSearch.EarlyExitCondition GetEarlyExitCondition(EarlyExitCondition condtion)
 {
     if (condtion == EarlyExitCondition.GoalTerrain)
     {
         return(GoalTerrainEarlyExit);
     }
     else
     {
         return(null);
     }
 }
 private static bool CheckForGoal(Node currentNode, EarlyExitCondition earlyExit)
 {
     if (earlyExit != null)
     {
         if (earlyExit(currentNode.coords) && Utility.ManhattanDistance(startPoint, currentNode.coords) > 10)
         {
             Debug.Log("EarlyExit!");
         }
         return((earlyExit(currentNode.coords) && Utility.ManhattanDistance(startPoint, currentNode.coords) > 10) || currentNode.coords.IsSamePoint(goalPoint));
     }
     else
     {
         return(currentNode.coords.IsSamePoint(goalPoint));
     }
 }
    public static List <Point> FindPath(Point start, Point goal, TraversableCondition isTraversableCondition, ExternalCostFactor externalCostOffset = null, EarlyExitCondition earlyExit = null)
    {
        //Caching Parameters for the other methods
        startPoint = start;
        goalPoint  = goal;
        List <Node> openList   = new List <Node>();
        List <Node> closedList = new List <Node>();

        Node startNode = GetNodeFromPoint(start);

        openList.Add(startNode);

        while (openList.Count > 0)
        {
            Node currentNode = GetLowestFCostNode(openList);

            if (CheckForGoal(currentNode, earlyExit)) //Early Exit when found
            {
                //Reconstruct path
                return(RetracePath(startNode, currentNode));
            }
            openList.Remove(currentNode);
            closedList.Add(currentNode);
            List <Node> neighbours = GetNeighbours(currentNode);

            foreach (Node neighbour in neighbours)
            {
                if (closedList.Contains(neighbour) || !isTraversableCondition(neighbour.coords))
                {
                    continue;
                }

                float newCost = currentNode.g + Utility.ManhattanDistance(currentNode.coords, neighbour.coords);
                if (externalCostOffset != null)
                {
                    newCost += externalCostOffset(currentNode.coords, neighbour.coords);
                }

                if (newCost < neighbour.g || !openList.Contains(neighbour))
                {
                    neighbour.g      = newCost;
                    neighbour.h      = Utility.ManhattanDistance(neighbour.coords, goal);
                    neighbour.parent = currentNode;

                    if (!openList.Contains(neighbour))
                    {
                        openList.Add(neighbour);
                    }
                }
            }
        }
        Debug.Log("No Road Found");
        return(new List <Point>());
    }