Beispiel #1
0
 public ParamBase(BaseGrid iGrid, HeuristicMode iMode)
 {
     SetHeuristic(iMode);
     m_searchGrid = iGrid;
     m_startNode  = null;
     m_endNode    = null;
 }
        public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint=true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
        {
            switch (iMode)
            {
                case HeuristicMode.MANHATTAN:
                    m_heuristic = new HeuristicDelegate(Heuristic.Manhattan);
                    break;
                case HeuristicMode.EUCLIDEAN:
                    m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                    break;
                case HeuristicMode.CHEBYSHEV:
                    m_heuristic = new HeuristicDelegate(Heuristic.Chebyshev);
                    break;
                default:
                    m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                    break;
            }
            m_allowEndNodeUnWalkable = iAllowEndNodeUnWalkable;
            m_crossAdjacentPoint = iCrossAdjacentPoint;
            m_crossCorner = iCrossCorner;

            openList = new List<Node>();

            m_searchGrid = iGrid;
            m_startNode = null;
            m_endNode = null;
            m_useRecursive = false;
        }
        public JumpPointParam(BaseGrid iGrid, bool iCrossCorner = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
        {
            switch (iMode)
            {
                case HeuristicMode.MANHATTAN:
                    heuristic = new HeuristicDelegate(Heuristic.Manhattan);
                    break;
                case HeuristicMode.EUCLIDEAN:
                    heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                    break;
                case HeuristicMode.CHEBYSHEV:
                    heuristic = new HeuristicDelegate(Heuristic.Chebyshev);
                    break;
                default:
                    heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                    break;
            }
            crossCorner = iCrossCorner;

            openList = new List<Node>();

            searchGrid = iGrid;
            startNode = null;
            endNode = null;
        }
Beispiel #4
0
            /// <summary>
            /// Returns the predicted distance from start to end based on the given heuristic mode.
            /// </summary>
            /// <param name="start">Start position.</param>
            /// <param name="end">End position.</param>
            /// <param name="mode">Heuristic mode.</param>
            public static float GetHeuristic(Vector3 start, Vector3 end, HeuristicMode mode)
            {
                if (mode == HeuristicMode.euclidian)
                {
                    return(Vector3.Distance(start, end));
                }
                if (mode == HeuristicMode.manhattan)
                {
                    return((Mathf.Abs(end.x - start.x) + Mathf.Abs(end.y - start.y) + Mathf.Abs(end.z - start.z)));
                }

                if (mode == HeuristicMode.hexagonal)
                {
                                        #if HEXAGONAL
                    return((Mathf.Abs(Vector3.Dot(end - start, Hexagonal.HexGrid.cornerUpRight)) * Vector3.Distance(end, start) +
                            Mathf.Abs(Vector3.Dot(end - start, Hexagonal.HexGrid.cornerDownRight)) * Vector3.Distance(end, start) +
                            Mathf.Abs(Vector3.Dot(end - start, Hexagonal.HexGrid.cornerLeft)) * Vector3.Distance(end, start)) / 2f);
                                        #else
                    Debug.LogError("JBirdAI: Trying to use hexagonal heuristic, but HEXAGONAL is not defined in the JBirdAI script.");
                    return(0f);
                                        #endif
                }
                else
                {
                    Debug.LogError("JBirdEngine.AIHelper: Attempting to use unimplemented Heuristic Mode!");
                    return(0f);
                }
            }
		protected override void Reset () {
			base.Reset();
			pathsForAll = true;
			chosenTarget = -1;
			sequentialTarget = 0;
			inverted = true;
			heuristicMode = HeuristicMode.Sequential;
		}
Beispiel #6
0
        public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
            : base(iGrid, iMode)
        {
            CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable ? EndNodeUnWalkableTreatment.ALLOW : EndNodeUnWalkableTreatment.DISALLOW;

            openList         = new IntervalHeap <Node>();
            CurIterationType = IterationType.LOOP;
        }
Beispiel #7
0
        protected ParamBase(BaseGrid iGrid, DiagonalMovement iDiagonalMovement, HeuristicMode iMode)
        {
            SetHeuristic(iMode);

            MsearchGrid      = iGrid;
            DiagonalMovement = iDiagonalMovement;
            MstartNode       = null;
            MendNode         = null;
        }
        protected ParamBase(BaseGrid grid, DiagonalMovement diagonalMovement, HeuristicMode mode)
        {
            SetHeuristic(mode);

            searchGrid       = grid;
            DiagonalMovement = diagonalMovement;
            startNode        = null;
            endNode          = null;
        }
Beispiel #9
0
        public ParamBase(BaseGrid iGrid, DiagonalMovement iDiagonalMovement, HeuristicMode iMode)
        {
            SetHeuristic(iMode);

            m_searchGrid     = iGrid;
            DiagonalMovement = iDiagonalMovement;
            m_startNode      = null;
            m_endNode        = null;
        }
Beispiel #10
0
    // Force Directed movement
    public static List <Tuple2 <Tuple3 <int> > > ForceDirected(Maze m, HeuristicMode hm)
    {
        // Number each block in the current state and map it in the bool[, ,]
        Block[, ,] originalMap = m.GetBlockMaze();
        Dictionary <int, Tuple3 <int> > currentBlockMap = new Dictionary <int, Tuple3 <int> > ();

        bool[, ,] currentMap = new bool[originalMap.GetLength(0), originalMap.GetLength(1), originalMap.GetLength(2)];

        int currentNumber = 0;

        for (int i = 0; i < originalMap.GetLength(0); ++i)
        {
            for (int j = 0; j < originalMap.GetLength(1); ++j)
            {
                for (int k = 0; k < originalMap.GetLength(2); ++k)
                {
                    if (originalMap [i, j, k] != null)
                    {
                        currentBlockMap.Add(currentNumber++, new Tuple3 <int> (i, j, k));
                    }
                    else
                    {
                        currentMap [i, j, k] = true;
                    }
                }
            }
        }

        // Number each block in the target state
        bool[, ,] targetMap = m.GetBlockMap();
        Dictionary <int, Tuple3 <int> > targetBlockMap = new Dictionary <int, Tuple3 <int> > ();
        int targetNumber = 0;

        for (int i = 0; i < targetMap.GetLength(0); ++i)
        {
            for (int j = 0; j < targetMap.GetLength(1); ++j)
            {
                for (int k = 0; k < targetMap.GetLength(2); ++k)
                {
                    if (!targetMap [i, j, k])
                    {
                        targetBlockMap.Add(targetNumber++, new Tuple3 <int>(i, j, k));
                    }
                }
            }
        }

        List <Tuple2 <Tuple3 <int> > > moves = new List <Tuple2 <Tuple3 <int> > >();

        for (int i = 0; i < currentBlockMap.Count; ++i)
        {
            moves.Add(new Tuple2 <Tuple3 <int> > (currentBlockMap [i], targetBlockMap [i]));
        }

        return(moves);
    }
Beispiel #11
0
        public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, bool iAllowEndNodeUnWalkable = true, 
			bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
			: this(iGrid, iAllowEndNodeUnWalkable, iCrossCorner, iCrossAdjacentPoint, iMode)
        {
            m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y);
            m_endNode = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y);
            if (m_startNode == null)
                m_startNode = new Node(iStartPos.x, iStartPos.y, true);
            if (m_endNode == null)
                m_endNode = new Node(iEndPos.x, iEndPos.y, true);            
        }
Beispiel #12
0
 public ParamBase(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, HeuristicMode iMode) : this(iGrid, iMode)
 {
     m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y);
     m_endNode   = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y);
     if (m_startNode == null)
     {
         m_startNode = new Node(iStartPos.x, iStartPos.y, true);
     }
     if (m_endNode == null)
     {
         m_endNode = new Node(iEndPos.x, iEndPos.y, true);
     }
 }
Beispiel #13
0
        public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint=true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
        {
			SetHeuristic(iMode);            
            m_allowEndNodeUnWalkable = iAllowEndNodeUnWalkable;
            m_crossAdjacentPoint = iCrossAdjacentPoint;
            m_crossCorner = iCrossCorner;

            openList = new List<Node>();

            m_searchGrid = iGrid;
            m_startNode = null;
            m_endNode = null;
            m_useRecursive = false;
        }
        public JumpPointParam(
            IBaseGrid iGrid,
            GridPos iStartPos,
            GridPos iEndPos,
            bool iAllowEndNodeUnWalkable = true,
            bool iCrossCorner = true,
            bool iCrossAdjacentPoint = true,
            HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
        {
            switch (iMode)
            {
                case HeuristicMode.MANHATTAN:
                    this.m_heuristic = new HeuristicDelegate(Heuristic.Manhattan);
                    break;
                case HeuristicMode.EUCLIDEAN:
                    this.m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                    break;
                case HeuristicMode.CHEBYSHEV:
                    this.m_heuristic = new HeuristicDelegate(Heuristic.Chebyshev);
                    break;
                default:
                    this.m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                    break;
            }
            this.m_allowEndNodeUnWalkable = iAllowEndNodeUnWalkable;
            this.m_crossAdjacentPoint = iCrossAdjacentPoint;
            this.m_crossCorner = iCrossCorner;
            this.openList = new List<Node>();

            this.m_searchGrid = iGrid;
            this.m_startNode = this.m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y);
            this.m_endNode = this.m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y);
            if (this.m_startNode == null)
            {
                this.m_startNode = new Node(iStartPos.x, iStartPos.y, true);
            }
            if (this.m_endNode == null)
            {
                this.m_endNode = new Node(iEndPos.x, iEndPos.y, true);
            }
            this.m_useRecursive = false;
        }
Beispiel #15
0
        public void SetHeuristic(HeuristicMode iMode)
        {
            m_heuristic = null;
            switch (iMode)
            {
            case HeuristicMode.MANHATTAN:
                m_heuristic = new HeuristicDelegate(Heuristic.Manhattan);
                break;

            case HeuristicMode.EUCLIDEAN:
                m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                break;

            case HeuristicMode.CHEBYSHEV:
                m_heuristic = new HeuristicDelegate(Heuristic.Chebyshev);
                break;

            default:
                m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                break;
            }
        }
Beispiel #16
0
        public void SetHeuristic(HeuristicMode iMode)
        {
            MHeuristic = null;
            switch (iMode)
            {
            case HeuristicMode.Manhattan:
                MHeuristic = new HeuristicDelegate(Heuristic.Manhattan);
                break;

            case HeuristicMode.Euclidean:
                MHeuristic = new HeuristicDelegate(Heuristic.Euclidean);
                break;

            case HeuristicMode.Chebyshev:
                MHeuristic = new HeuristicDelegate(Heuristic.Chebyshev);
                break;

            default:
                MHeuristic = new HeuristicDelegate(Heuristic.Euclidean);
                break;
            }
        }
Beispiel #17
0
        public void SetHeuristic(HeuristicMode iMode)
        {
            Mheuristic = null;
            switch (iMode)
            {
            case HeuristicMode.Manhattan:
                Mheuristic = Heuristic.Manhattan;
                break;

            case HeuristicMode.Euclidean:
                Mheuristic = Heuristic.Euclidean;
                break;

            case HeuristicMode.Chebyshev:
                Mheuristic = Heuristic.Chebyshev;
                break;

            default:
                Mheuristic = Heuristic.Euclidean;
                break;
            }
        }
Beispiel #18
0
        public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
            : base(iGrid, iMode)
        {
            m_allowEndNodeUnWalkable = iAllowEndNodeUnWalkable;
            m_crossAdjacentPoint     = iCrossAdjacentPoint;
            m_crossCorner            = iCrossCorner;

            openList       = new IntervalHeap <Node>();
            m_useRecursive = false;
        }
Beispiel #19
0
        public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, EndNodeUnWalkableTreatment iAllowEndNodeUnWalkable = EndNodeUnWalkableTreatment.Allow, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.Euclidean)
            : base(iGrid, iStartPos, iEndPos, iDiagonalMovement, iMode)
        {
            CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable;
            openList = new IntervalHeap <Node>();

            CurIterationType = IterationType.Loop;
        }
Beispiel #20
0
 public void SetHeuristic(HeuristicMode mode)
 => heuristic = mode switch
 {
Beispiel #21
0
        protected ParamBase(BaseGrid grid, GridPos startPos, GridPos endPos, DiagonalMovement diagonalMovement, HeuristicMode mode) : this(grid, diagonalMovement, mode)
        {
            startNode = searchGrid.GetNodeAt(startPos.X, startPos.Y);
            endNode   = searchGrid.GetNodeAt(endPos.X, endPos.Y);

            if (startNode == null)
            {
                startNode = new Node(startPos.X, startPos.Y, true);
            }

            if (endNode == null)
            {
                endNode = new Node(endPos.X, endPos.Y, true);
            }
        }
Beispiel #22
0
        public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, EndNodeUnWalkableTreatment iAllowEndNodeUnWalkable = EndNodeUnWalkableTreatment.ALLOW, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
            : base(iGrid, iStartPos, iEndPos, iMode)
        {
            CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable;
            openList = new IntervalHeap <Node>();

            CurIterationType = IterationType.LOOP;
        }
Beispiel #23
0
        public JumpPointParam(BaseGrid grid, EndNodeUnWalkableTreatment allowEndNodeUnWalkable = EndNodeUnWalkableTreatment.Allow, DiagonalMovement diagonalMovement = DiagonalMovement.Always, HeuristicMode mode = HeuristicMode.Euclidean)
            : base(grid, diagonalMovement, mode)
        {
            CurEndNodeUnWalkableTreatment = allowEndNodeUnWalkable;

            OpenList         = new IntervalHeap <Node>();
            CurIterationType = IterationType.Loop;
        }
 public void SetHeuristic(HeuristicMode iMode)
 {
     heuristic = null;
     switch (iMode)
     {
         case HeuristicMode.MANHATTAN:
             heuristic = new HeuristicDelegate(Heuristic.Manhattan);
             break;
         case HeuristicMode.EUCLIDEAN:
             heuristic = new HeuristicDelegate(Heuristic.Euclidean);
             break;
         case HeuristicMode.CHEBYSHEV:
             heuristic = new HeuristicDelegate(Heuristic.Chebyshev);
             break;
         default:
             heuristic = new HeuristicDelegate(Heuristic.Euclidean);
             break;
     }
 }
Beispiel #25
0
 public void SetHeuristic(HeuristicMode iMode)
 {
     m_heuristic = null;
     m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
 }
Beispiel #26
0
 public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, bool iAllowEndNodeUnWalkable = true,
                       bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
     : this(iGrid, iAllowEndNodeUnWalkable, iCrossCorner, iCrossAdjacentPoint, iMode)
 {
     m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y);
     m_endNode   = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y);
     if (m_startNode == null)
     {
         m_startNode = new Node(iStartPos.x, iStartPos.y, true);
     }
     if (m_endNode == null)
     {
         m_endNode = new Node(iEndPos.x, iEndPos.y, true);
     }
 }
Beispiel #27
0
 public AStarParam(BaseGrid iGrid, float iweight, DiagonalMovement iDiagonalMovement = DiagonalMovement.IfAtLeastOneWalkable, HeuristicMode iMode = HeuristicMode.Euclidean)
     : base(iGrid, iDiagonalMovement, iMode)
 {
     Weight = iweight;
 }
        public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
        {
            switch (iMode)
            {
            case HeuristicMode.MANHATTAN:
                m_heuristic = new HeuristicDelegate(Heuristic.Manhattan);
                break;

            case HeuristicMode.EUCLIDEAN:
                m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                break;

            case HeuristicMode.CHEBYSHEV:
                m_heuristic = new HeuristicDelegate(Heuristic.Chebyshev);
                break;

            default:
                m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
                break;
            }
            m_allowEndNodeUnWalkable = iAllowEndNodeUnWalkable;
            m_crossAdjacentPoint     = iCrossAdjacentPoint;
            m_crossCorner            = iCrossCorner;

            openList = new List <Node>();

            m_searchGrid   = iGrid;
            m_startNode    = null;
            m_endNode      = null;
            m_useRecursive = false;
        }
Beispiel #29
0
        public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
        {
            SetHeuristic(iMode);
            m_allowEndNodeUnWalkable = iAllowEndNodeUnWalkable;
            m_crossAdjacentPoint     = iCrossAdjacentPoint;
            m_crossCorner            = iCrossCorner;

            openList = new List <Node>();

            m_searchGrid   = iGrid;
            m_startNode    = null;
            m_endNode      = null;
            m_useRecursive = false;
        }
 public AStarParam(BaseGrid iGrid, float iweight, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
     : base(iGrid, iDiagonalMovement, iMode)
 {
     Weight = iweight;
 }
Beispiel #31
0
		public AStarParam(BaseGrid grid, GridPos startPos, GridPos endPos, float weight, DiagonalMovement diagonalMovement = DiagonalMovement.Always, HeuristicMode mode = HeuristicMode.Euclidean)
			: base(grid, startPos, endPos, diagonalMovement, mode)
			=> Weight = weight;
Beispiel #32
0
 protected ParamBase(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, DiagonalMovement iDiagonalMovement, HeuristicMode iMode) : this(iGrid, iDiagonalMovement, iMode)
 {
     MstartNode = MsearchGrid.GetNodeAt(iStartPos.X, iStartPos.Y);
     MendNode   = MsearchGrid.GetNodeAt(iEndPos.X, iEndPos.Y);
     if (MstartNode == null)
     {
         MstartNode = new Node(iStartPos.X, iStartPos.Y, true);
     }
     if (MendNode == null)
     {
         MendNode = new Node(iEndPos.X, iEndPos.Y, true);
     }
 }
 public JumpPointParam(BaseGrid iGrid, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
     : base(iGrid, iDiagonalMovement, iMode)
 {
     openList         = new IntervalHeap <Node>();
     CurIterationType = IterationType.LOOP;
 }
Beispiel #34
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;
 }
 public AStarParam(BaseGrid iGrid, float iweight, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
     : base(iGrid, iMode)
 {
     Weight = iweight;
 }
Beispiel #36
0
 protected ParamBase(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, DiagonalMovement iDiagonalMovement, HeuristicMode iMode) : this(iGrid, iDiagonalMovement, iMode)
 {
     m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y);
     m_endNode   = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y);
     if (m_startNode == null)
     {
         m_startNode = new Node(iStartPos.x, iStartPos.y, true);
     }
     if (m_endNode == null)
     {
         m_endNode = new Node(iEndPos.x, iEndPos.y, true);
     }
 }