/// <summary>
 /// Idea of this function: You give it a function that has captured local variables so you can
 /// run whatever you want on all nodes that are in range of a given node.
 /// </summary>
 /// <param name="listNodes">Look at all nodes in range of this node.</param>
 /// <param name="minDist">Minimum firing distance.</param>
 /// <param name="maxDist">Maximum firing distance.</param>
 /// <param name="funcToRun">What function we should run on the nodes in range.</param>
 public void runFuncOnAllNodesInRangeOfNode(Node n, int minDist, int maxDist, System.Action<Node> funcToRun)
 {
     runFuncOnAllNodesInRangeOfNode(funcToRun, n.getGridPos().x, n.getGridPos().y, minDist, maxDist);
 }
        /// <summary>
        /// Note: This calculates the diagonal distance heuristic.
        /// Taken from http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html.
        /// </summary>
        /// <param name="startNode">Start node</param>
        /// <param name="endNode">End node</param>
        /// <returns></returns>
        public float DiagonalHeuristic(Node startNode, Node endNode)
        {
            float distX = Mathf.Abs(startNode.getGridPos().x - endNode.getGridPos().x);
            float distY = Mathf.Abs(startNode.getGridPos().y - endNode.getGridPos().y);

            return distX + distY - (2 - sqrt2) * Mathf.Min(distX, distY);
        }
        /// <summary>
        /// Note: This calculates the manhatten distance heuristic.
        /// </summary>
        /// <param name="startNode">Start node</param>
        /// <param name="endNode">End node</param>
        /// <returns></returns>
        public float ManhattenHeuristic(Node startNode, Node endNode)
        {
            int distX = Mathf.Abs(startNode.getGridPos().x - endNode.getGridPos().x);
            int distY = Mathf.Abs(startNode.getGridPos().y - endNode.getGridPos().y);

            return distX + distY;
        }
Exemple #4
0
        public static int range(Node a, Node b)
        {
            int rX = a.getGridPos().x - b.getGridPos().x;
            int rY = a.getGridPos().y - b.getGridPos().y;

            if (rX < 0)
                rX = -rX;
            if (rY < 0)
                rY = -rY;

            return rX + rY;
        }