Exemple #1
0
        public Node SetNode(int iX, int iY, int iZ, bool?iWalkable = null)
        {
            GridPos pos = new GridPos(iX, iY, iZ);

            return(SetNode(pos, iWalkable));
        }
Exemple #2
0
        protected void removeNode(int iX, int iY, int iZ)
        {
            GridPos pos = new GridPos(iX, iY, iZ);

            removeNode(pos);
        }
Exemple #3
0
        public Node GetNode(int iX, int iY, int iZ)
        {
            GridPos pos = new GridPos(iX, iY, iZ);

            return(GetNode(pos));
        }
 public override bool IsWalkableAt(GridPos iPos)
 {
     return(m_nodes.ContainsKey(iPos));
 }
 public override bool SetWalkableAt(GridPos iPos, bool iWalkable)
 {
     return(SetWalkableAt(iPos.x, iPos.y, iPos.z, iWalkable));
 }
        public override Node GetNodeAt(int iX, int iY, int iZ)
        {
            GridPos pos = new GridPos(iX, iY, iZ);

            return(GetNodeAt(pos));
        }
        public override bool IsWalkableAt(int iX, int iY, int iZ)
        {
            GridPos pos = new GridPos(iX, iY, iZ);

            return(IsWalkableAt(pos));
        }
Exemple #8
0
        /*      UPPER                    MIDDLE                   LOWER
         * **********************   *******************   **********************
         * * tDU3 * tSU2 * tDU2 *   * tD3 * tS2 * tD2 *   * tDD3 * tSD2 * tDD2 *
         * **********************   *******************   **********************
         * * tSU3 * tS4  * tSU1 *   * tS3 * Cur * tS1 *   * tSD3 * tS5  * tSD1 *
         * **********************   *******************   **********************
         * * tDU0 * tSU0 * tDU1 *   * tD0 * tS0 * tD1 *   * tDD0 * tSD0 * tDD1 *
         * **********************   *******************   **********************
         */

        public List <Node> GetNeighbors(Node iNode, DiagonalMovement diagonalMovement)
        {
            int         tX = iNode.x;
            int         tY = iNode.y;
            int         tZ = iNode.z;
            List <Node> neighbors = new List <Node>();
            bool        tS0 = false, tD0 = false,
                        tS1 = false, tD1 = false,
                        tS2 = false, tD2 = false,
                        tS3 = false, tD3 = false,
                        tS4 = false,
                        tS5 = false,

                        tSU0 = false,
                        tSU1 = false,
                        tSU2 = false,
                        tSU3 = false,
                        tDU0 = false,
                        tDU1 = false,
                        tDU2 = false,
                        tDU3 = false,

                        tSD0 = false,
                        tSD1 = false,
                        tSD2 = false,
                        tSD3 = false,
                        tDD0 = false,
                        tDD1 = false,
                        tDD2 = false,
                        tDD3 = false;

            GridPos pos = new GridPos();

            if (this.IsWalkableAt(pos.Set(tX, tY - 1, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
                tS0 = true;
            }
            if (this.IsWalkableAt(pos.Set(tX + 1, tY, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
                tS1 = true;
            }
            if (this.IsWalkableAt(pos.Set(tX, tY + 1, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
                tS2 = true;
            }
            if (this.IsWalkableAt(pos.Set(tX - 1, tY, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
                tS3 = true;
            }
            if (this.IsWalkableAt(pos.Set(tX, tY, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
                tS4 = true;
            }
            if (this.IsWalkableAt(pos.Set(tX, tY, tZ - 1)))
            {
                neighbors.Add(GetNodeAt(pos));
                tS5 = true;
            }

            switch (diagonalMovement)
            {
            case DiagonalMovement.Always:
                tD0 = true;
                tD1 = true;
                tD2 = true;
                tD3 = true;
                break;

            case DiagonalMovement.Never:
                break;

            case DiagonalMovement.IfAtLeastOneWalkable:
                tD0 = tS3 || tS0;
                tD1 = tS0 || tS1;
                tD2 = tS1 || tS2;
                tD3 = tS2 || tS3;
                break;

            case DiagonalMovement.OnlyWhenNoObstacles:
                tD0 = tS3 && tS0;
                tD1 = tS0 && tS1;
                tD2 = tS1 && tS2;
                tD3 = tS2 && tS3;
                break;

            default:
                break;
            }

            if (tD0 && this.IsWalkableAt(pos.Set(tX - 1, tY - 1, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tD0 = false;
            }
            if (tD1 && this.IsWalkableAt(pos.Set(tX + 1, tY - 1, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tD1 = false;
            }
            if (tD2 && this.IsWalkableAt(pos.Set(tX + 1, tY + 1, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tD2 = false;
            }
            if (tD3 && this.IsWalkableAt(pos.Set(tX - 1, tY + 1, tZ)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tD3 = false;
            }

            switch (diagonalMovement)
            {
            case DiagonalMovement.Always:

                tSU0 = true;
                tSU1 = true;
                tSU2 = true;
                tSU3 = true;

                tSD0 = true;
                tSD1 = true;
                tSD2 = true;
                tSD3 = true;
                break;

            case DiagonalMovement.Never:
                break;

            case DiagonalMovement.IfAtLeastOneWalkable:
                tSU0 = tS0 || tS4;
                tSU1 = tS1 || tS4;
                tSU2 = tS2 || tS4;
                tSU3 = tS3 || tS4;

                tSD0 = tS0 || tS4;
                tSD1 = tS1 || tS4;
                tSD2 = tS2 || tS4;
                tSD3 = tS3 || tS4;

                break;

            case DiagonalMovement.OnlyWhenNoObstacles:
                tSU0 = tS0 && tS4;
                tSU1 = tS1 && tS4;
                tSU2 = tS2 && tS4;
                tSU3 = tS3 && tS4;

                tSD0 = tS0 && tS4;
                tSD1 = tS1 && tS4;
                tSD2 = tS2 && tS4;
                tSD3 = tS3 && tS4;
                break;

            default:
                break;
            }

            if (tSU0 && this.IsWalkableAt(pos.Set(tX, tY - 1, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSU0 = false;
            }
            if (tSU1 && this.IsWalkableAt(pos.Set(tX + 1, tY, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSU1 = false;
            }
            if (tSU2 && this.IsWalkableAt(pos.Set(tX, tY + 1, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSU2 = false;
            }
            if (tSU3 && this.IsWalkableAt(pos.Set(tX - 1, tY, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSU3 = false;
            }

            if (tSD0 && this.IsWalkableAt(pos.Set(tX, tY - 1, tZ - 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSD0 = false;
            }
            if (tSD1 && this.IsWalkableAt(pos.Set(tX + 1, tY, tZ - 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSD1 = false;
            }
            if (tSD2 && this.IsWalkableAt(pos.Set(tX, tY + 1, tZ - 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSD2 = false;
            }
            if (tSD3 && this.IsWalkableAt(pos.Set(tX - 1, tY, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            else
            {
                tSD3 = false;
            }

            switch (diagonalMovement)
            {
            case DiagonalMovement.Always:
                tDU0 = true;
                tDU1 = true;
                tDU2 = true;
                tDU3 = true;

                tDD0 = true;
                tDD1 = true;
                tDD2 = true;
                tDD3 = true;
                break;

            case DiagonalMovement.Never:
                break;

            case DiagonalMovement.IfAtLeastOneWalkable:
                tDU0 = tS0 || tS3 || tSU0 || tSU3;    // || tD0 || tS4;
                tDU1 = tS0 || tS1 || tSU0 || tSU1;    // || tD1 || tS4;
                tDU2 = tS2 || tS3 || tSU2 || tSU3;    // || tD3 || tS4;
                tDU3 = tS1 || tS2 || tSU1 || tSU2;    // || tD2 || tS4;

                tDD0 = tS0 || tS3 || tSD0 || tSD3;    // || tD0 || tS5;
                tDD1 = tS0 || tS1 || tSD0 || tSD1;    // || tD1 || tS5;
                tDD2 = tS2 || tS3 || tSD2 || tSD3;    // || tD3 || tS5;
                tDD3 = tS1 || tS2 || tSD1 || tSD2;    // || tD2 || tS5;

                break;

            case DiagonalMovement.OnlyWhenNoObstacles:
                tDU0 = tS0 && tS3 && tSU0 && tSU3 && tD0 && tS4;
                tDU1 = tS0 && tS1 && tSU0 && tSU1 && tD1 && tS4;
                tDU2 = tS2 && tS3 && tSU2 && tSU3 && tD3 && tS4;
                tDU3 = tS1 && tS2 && tSU1 && tSU2 && tD2 && tS4;

                tDD0 = tS0 && tS3 && tSD0 && tSD3 && tD0 && tS5;
                tDD1 = tS0 && tS1 && tSD0 && tSD1 && tD1 && tS5;
                tDD2 = tS2 && tS3 && tSD2 && tSD3 && tD3 && tS5;
                tDD3 = tS1 && tS2 && tSD1 && tSD2 && tD2 && tS5;
                break;

            default:
                break;
            }

            if (tDU0 && this.IsWalkableAt(pos.Set(tX - 1, tY - 1, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            if (tDU1 && this.IsWalkableAt(pos.Set(tX + 1, tY - 1, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            if (tDU2 && this.IsWalkableAt(pos.Set(tX + 1, tY + 1, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            if (tDU3 && this.IsWalkableAt(pos.Set(tX - 1, tY + 1, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }

            if (tDD0 && this.IsWalkableAt(pos.Set(tX - 1, tY - 1, tZ - 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            if (tDD1 && this.IsWalkableAt(pos.Set(tX + 1, tY - 1, tZ - 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            if (tDD2 && this.IsWalkableAt(pos.Set(tX + 1, tY + 1, tZ - 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            if (tDD3 && this.IsWalkableAt(pos.Set(tX - 1, tY + 1, tZ + 1)))
            {
                neighbors.Add(GetNodeAt(pos));
            }
            return(neighbors);
        }
 internal abstract void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null);
Exemple #10
0
 public abstract bool SetWalkableAt(GridPos iPos, bool iWalkable);
Exemple #11
0
 public abstract bool IsWalkableAt(GridPos iPos);
Exemple #12
0
 public abstract Node GetNodeAt(GridPos iPos);
Exemple #13
0
        internal override void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null)
        {

        }
Exemple #14
0
 public AStarParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, float iweight, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
     : base(iGrid, iStartPos, iEndPos, iDiagonalMovement, iMode)
 {
     Weight = iweight;
 }