Ejemplo n.º 1
0
        public Node(Node parent, GridHexagon piece)
        {
            this.Parent = parent;
            // array index of this Node in the world linear array

            // the location coordinates of this Node
            this.X    = piece.X;
            this.Y    = piece.Z;
            this.Item = piece;
            // the distanceFunction cost to get
            // TO this Node from the START
            this.F = 0;
            // the distanceFunction cost to get
            // from this Node to the GOAL
            this.G = 0;
        }
Ejemplo n.º 2
0
        public static int Distance(GridHexagon p1, GridHexagon p2)
        {
            var x1 = p1.X;
            var y1 = p1.Z;

            var x2 = p2.X;
            var y2 = p2.Z;

            var du = x2 - x1;
            var dv = (y2 + ((x2 / 2) | 0)) - (y1 + ((x1 / 2) | 0));

            if ((du >= 0 && dv >= 0) || (du < 0 && dv < 0))
            {
                return(Math.Max(Math.Abs(du), Math.Abs(dv)));
            }
            else
            {
                return(Math.Abs(du) + Math.Abs(dv));
            }
        }
Ejemplo n.º 3
0
        public static Direction GetDirection(GridHexagon p1, GridHexagon p2)
        {
            // console.log('x1', p1.x, 'x2', p2.x, 'y1', p1.z, 'y2', p2.z);
            string upDown    = null;
            string leftRight = null;


            if (p1.X % 2 == 0)
            {
                if (p1.Z == p2.Z)
                {
                    upDown = "up";
                }
                else if (p1.Z < p2.Z)
                {
                    upDown = "down";
                }
                else if (p1.Z > p2.Z)
                {
                    upDown = "up";
                }
            }
            else
            {
                if (p1.Z == p2.Z)
                {
                    upDown = "down";
                }
                else if (p1.Z < p2.Z)
                {
                    upDown = "down";
                }
                else if (p1.Z > p2.Z)
                {
                    upDown = "up";
                }
            }


            if (p1.X < p2.X)
            {
                leftRight = "right";
            }
            else if (p1.X > p2.X)
            {
                leftRight = "left";
            }
            else
            {
                leftRight = "neither";
            }
            switch (leftRight)
            {
            case "left":
                switch (upDown)
                {
                case "up":
                    return(Direction.TopLeft);

                case "down":
                    return(Direction.BottomLeft);
                }
                break;

            case "right":
                switch (upDown)
                {
                case "up":
                    return(Direction.TopRight);

                case "down":
                    return(Direction.BottomRight);
                }
                break;

            case "neither":
                switch (upDown)
                {
                case "up":
                    return(Direction.Top);

                case "down":
                    return(Direction.Bottom);
                }
                break;
            }
            return(Direction.Top);
        }