Exemplo n.º 1
0
    public List <GridPos> FindPath(Vector2 p1, Vector2 p2)
    {
        var jpParam = new JumpPointParam(grids, new GridPos(Convert.ToInt32(p1.x), Convert.ToInt32(p1.y)), new GridPos(Convert.ToInt32(p2.x), Convert.ToInt32(p2.y)));
        var path    = JumpPointFinder.FindPath(jpParam);

        return(path);
    }
Exemplo n.º 2
0
        public IList <Point2D> GetPath(int[][] grid, Point2D start, Point2D end, GameDiagonalMovement type)
        {
            var width  = grid.Length;
            var height = grid[0].Length;

            bool[][] movableMatrix = new bool[width][];
            for (int widthTrav = 0; widthTrav < width; widthTrav++)
            {
                movableMatrix[widthTrav] = new bool[height];
                for (int heightTrav = 0; heightTrav < height; heightTrav++)
                {
                    movableMatrix[widthTrav][heightTrav] = grid[widthTrav][heightTrav] == 0;
                }
            }

            Board    = new StaticGrid(width, height, movableMatrix);
            StartPos = new GridPos(start.X, start.Y);
            EndPos   = new GridPos(end.X, end.Y);
            JumpPointParam jpParam = new JumpPointParam(Board, StartPos, EndPos, EndNodeUnWalkableTreatment.DISALLOW,
                                                        type == GameDiagonalMovement.Never ? DiagonalMovement.Never : DiagonalMovement.Always,
                                                        HeuristicMode.EUCLIDEAN);
            List <GridPos> resultPathList = JumpPointFinder.FindPath(jpParam);


            return(resultPathList.Select(x => new Point2D(x.x, x.y)).ToList());
        }
Exemplo n.º 3
0
        public List <MapCell> JPSPlus(MapCell cell1, MapCell cell2)
        {
            List <MapCell> path  = new List <MapCell>();
            List <GridPos> lpath = new List <GridPos>();

            if (cell1.MapId != cell2.MapId)
            {
                return(path);
            }
            JumpPointParam JumpPointParameters = new JumpPointParam(_tempgrid, new GridPos(cell1.X, cell1.Y), new GridPos(cell2.X, cell2.Y), false, true, true, HeuristicMode.MANHATTAN);
            List <GridPos> resultPathList      = JumpPointFinder.FindPath(JumpPointParameters);

            lpath = JumpPointFinder.GetFullPath(resultPathList);
            Debug.WriteLine($"From X: {cell1.X} Y: {cell1.Y}, To X: {cell2.X} Y: {cell2.Y}, Paths: {resultPathList.Count}, LPath: {lpath.Count}");
            if (lpath.Count > 0)
            {
                foreach (GridPos item in lpath)
                {
                    path.Add(new MapCell {
                        X = Convert.ToInt16(item.x), Y = Convert.ToInt16(item.y), MapId = cell1.MapId
                    });
                }
            }

            return(path);
        }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        m_hidden = new Color(1.0f, 1.0f, 1.0f, 0.0f);  //invisible
        m_basic  = new Color(1.0f, 1.0f, 1.0f, 0.03f); //visible

        m_start = new Color(Color.green.r, Color.green.g, Color.green.b, 1.0f);
        m_end   = new Color(Color.red.r, Color.red.g, Color.red.b, 1.0f);
        m_open  = new Color(Color.blue.r, Color.blue.g, Color.blue.b, 0.3f);
        m_close = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.3f);

        m_unwalkable = new Color(Color.black.r, Color.black.g, Color.black.b, 1.0f);


        //// UI ////
        //loading & mapping
        m_cube = Resources.Load("Prefabs/Cube") as GameObject;
        GameObject.Find("Canvas/btnClear").GetComponent <Button>().onClick.AddListener(OnbtnClearClicked);
        GameObject.Find("Canvas/btnSearch").GetComponent <Button>().onClick.AddListener(OnbtnSearchClicked);
        GameObject.Find("Canvas/btnLoadMap").GetComponent <Button>().onClick.AddListener(OnbtnLoadMapClicked);
        GameObject.Find("Canvas/btnLoadStartEnd").GetComponent <Button>().onClick.AddListener(OnbtnLoadStartEndClicked);
        m_ddDiagonalMode = GameObject.Find("Canvas/DropdownMode").GetComponent <Dropdown>();
        m_tRecursive     = GameObject.Find("Canvas/ToggleRecursive").GetComponent <Toggle>();
        m_tOpenedCell    = GameObject.Find("Canvas/ToggleOpenedCell").GetComponent <Toggle>();
        m_tTotalMap      = GameObject.Find("Canvas/ToggleTotalMap").GetComponent <Toggle>();

        m_tOpenedCell.onValueChanged.AddListener((value) => { OntOpenedCellValue(value); });
        m_tTotalMap.onValueChanged.AddListener((value) => { OntTotalMapValue(value); });



        ////cube setup////
        m_cubeMap = new Dictionary <int, GameObject>();
        int width = 10, length = 10, height = 10;

        buildCubes(width, length, height);

        ////Testbeds////
        //2 testbeds
        //m_testbedList.Add(new Testbed()); //default
        //m_testbedList.Add(new Testbed(new GridPos(1, 2, 3), new GridPos(9, 8, 7))); //custom

        ////path grid setup////
        //convert all matrix walkable
        bool[][][] movableMatrix = new bool [width][][];
        for (int widthTrav = 0; widthTrav < width; widthTrav++)
        {
            movableMatrix[widthTrav] = new bool[length][];
            for (int lengthTrav = 0; lengthTrav < length; lengthTrav++)
            {
                movableMatrix[widthTrav][lengthTrav] = new bool[height];
                for (int heightTrav = 0; heightTrav < height; heightTrav++)
                {
                    movableMatrix[widthTrav][lengthTrav][heightTrav] = true;
                }
            }
        }
        BaseGrid searchGrid      = new StaticGrid(width, length, height, movableMatrix);

        m_jumpParam = new JumpPointParam(searchGrid, new GridPos(), new GridPos(), EndNodeUnWalkableTreatment.ALLOW, DiagonalMovement.Always);
    }
Exemplo n.º 5
0
        private IList <GridPos> GetJumpPointsFromJumpPointFinder(Vector2Int startPoint, Vector2Int targetPoint)
        {
            if (!_gridInfoProvider.IsWalkable(targetPoint))
            {
                return(new GridPos[0]);
            }

            GridPos startPosition  = ZeroBasedPosition(startPoint);
            GridPos targetPosition = ZeroBasedPosition(targetPoint);

            // todo: when iAllowEndNodeUnWalkable is set to false, it seems that search is performed anyway — it just finishes with failure. Fix!
            JumpPointParam jumpPointsParams
                = new JumpPointParam(_navigationGrid, startPosition, targetPosition, iAllowEndNodeUnWalkable: false, iMode: HeuristicMode.MANHATTAN);

            // todo: note that resetting the grid causes all the nodes to be created again,
            // which probably causes bad performance (5-30 ms for 30x50 grid).
            // Possible solutions: use DynamicGridWPool instead of StaticGrid; refactor the library; use other library.
            jumpPointsParams.Reset(startPosition, targetPosition);
            IList <GridPos> resultPathList = JumpPointFinder.FindPath(jumpPointsParams);

            if (!resultPathList.Any())
            {
                return(new GridPos[0]);
            }
            return(resultPathList);
        }
Exemplo n.º 6
0
        public IEnumerable <Vector2D> Find(Vector2D origin, Vector2D destination)
        {
            BaseGrid searchGrid = new StaticGrid(map.Width, map.Height, matrix);
            var      jp         = new JumpPointParam(searchGrid, new GridPos(origin.X, origin.Y), new GridPos(destination.X, destination.Y), EndNodeUnWalkableTreatment.Allow);

            return(JumpPointFinder.FindPath(jp).Select(x => new Vector2D(x.X, x.Y)));
        }
Exemplo n.º 7
0
        public void LoadZone()
        {
            Stream stream = new MemoryStream(Data);

            byte[] bytes          = new byte[stream.Length];
            int    numBytesToRead = 1;
            int    numBytesRead   = 0;

            byte[] xlength = new byte[2];
            byte[] ylength = new byte[2];
            stream.Read(bytes, numBytesRead, numBytesToRead);
            xlength[0] = bytes[0];
            stream.Read(bytes, numBytesRead, numBytesToRead);
            xlength[1] = bytes[0];
            stream.Read(bytes, numBytesRead, numBytesToRead);
            ylength[0] = bytes[0];
            stream.Read(bytes, numBytesRead, numBytesToRead);
            ylength[1] = bytes[0];
            YLength    = BitConverter.ToInt16(ylength, 0);
            XLength    = BitConverter.ToInt16(xlength, 0);

            _grid = new short[XLength, YLength];
            for (int i = 0; i < YLength; ++i)
            {
                for (int t = 0; t < XLength; ++t)
                {
                    stream.Read(bytes, numBytesRead, numBytesToRead);
                    _grid[t, i] = Convert.ToInt16(bytes[0]);
                }
            }

            // initialize JPS
            _tempgrid           = ConvertToGrid(_grid);
            JumpPointParameters = new JumpPointParam(_tempgrid, new GridPos(0, 0), new GridPos(0, 0), false, true, true, HeuristicMode.MANHATTAN);
        }
Exemplo n.º 8
0
        public static List <GridPos> GetPath(Point2D start, Point2D end)
        {
            for (int i = 0; i < MovableMatrix.Length; i++)
            {
                var row = MovableMatrix[i];
                for (int index = 0; index < row.Length; index++)
                {
                    MovableMatrix[i][index] = true;
                }
            }

            List <CircularUnit> circularUnits = new List <CircularUnit>(Tick.World.Minions);

            circularUnits.AddRange(Tick.World.Buildings);
            circularUnits.AddRange(Tick.World.Wizards.Where(x => !x.IsMe));
            circularUnits.AddRange(Tick.World.Trees);
            circularUnits = circularUnits.Where(x => Tick.Self.GetDistanceTo(x) < Tick.Self.VisionRange).ToList();
            foreach (var nearestMinion in circularUnits)
            {
                var p1 = (int)nearestMinion.X / gridStep;
                var p2 = (int)nearestMinion.Y / gridStep;
                FillMovableCircle(p1, p2, (int)(nearestMinion.Radius + Tick.Self.Radius * 1.2) / gridStep, gridSize, MovableMatrix, false);
            }

            var startGridPos = GetGridPosByPoint2d(start, gridStep);
            var endGridPos   = GetGridPosByPoint2d(end, gridStep);

            MovableMatrix[startGridPos.x][startGridPos.y] = true;
            FillMovableCircle(endGridPos.x, endGridPos.y, (int)(Tick.Self.Radius * 2) / gridStep, gridSize, MovableMatrix, true);

            BaseGrid searchGrid = new StaticGrid(gridSize, gridSize, MovableMatrix);

            JumpPointParam jpParam = new JumpPointParam(searchGrid, startGridPos, endGridPos);
            var            result  = JumpPointFinder.FindPath(jpParam);

            //result = JumpPointFinder.GetFullPath(result);

            //var clmnIdx = 0;
            //foreach (var row in MovableMatrix)
            //{
            //    var rowIdx = 0;
            //    foreach (var b in row)
            //    {
            //        if (!b)
            //        {
            //            VisualClientHelper.Rect(new Point2D(clmnIdx * gridStep, rowIdx * gridStep),
            //                new Point2D((clmnIdx + 1) * gridStep, (rowIdx + 1) * gridStep), new VisualClientColor(0, 0, 1));
            //        }

            //        rowIdx++;
            //    }

            //    clmnIdx++;
            //}

            DrawPath(result, gridStep);

            return(result);
        }
Exemplo n.º 9
0
    private void Start()
    {
        SpawnPoint = transform.position;
        jpParam    = new JumpPointParam(MapLoader.maps[agent.session.map].aStar);

        skills_defense = agent.skills.ToList().FindAll(x => x.effectType == EffectType.Heal || x.effectType == EffectType.DamageShield).ToArray();
        skills_attack  = agent.skills.ToList().FindAll(x => x.effectType != EffectType.Heal && x.effectType != EffectType.DamageShield).ToArray();
    }
Exemplo n.º 10
0
 public Map(int width, int height)
 {
     _mapLayout   = new Tile[width, height];
     _searchGrid  = new StaticGrid(width, height);
     _width       = width;
     _height      = height;
     jpParam      = new JumpPointParam(null, true, false, false);
     _tileObjects = new List <TileObject>();
 }
Exemplo n.º 11
0
 public static List <GridPos> JPSPlus(JumpPointParam JumpPointParameters, GridPos cell1, GridPos cell2)
 {
     if (JumpPointParameters != null)
     {
         JumpPointParameters.Reset(cell1, cell2);
         return(JumpPointFinder.GetFullPath(JumpPointFinder.FindPath(JumpPointParameters)));
     }
     return(new List <GridPos>());
 }
        public void FindPath_Trivial()
        {
            var grid = new StaticGrid(3, 3);
            //grid.SetWalkableAll(true);
            var param = new JumpPointParam(grid, new GridPos(0, 0), new GridPos(2, 2));
            var path  = JumpPointFinder.FindPath(param);

            Assert.Contains(new GridPos(0, 0), path);
            Assert.Contains(new GridPos(2, 2), path);
        }
Exemplo n.º 13
0
        public Routing(GridPos theCurrent, GridPos theDestination, BaseGrid theGrid)
        {
            myCurrent     = theCurrent;
            myDestination = theDestination;

            theGrid.SetWalkableAt(theDestination, true);
            myGrid = new JumpPointParam(theGrid, true, DiagonalMovement.IfAtLeastOneWalkable);
            //myGrid.AllowEndNodeUnWalkable = true;


            GetNodes();
        }
Exemplo n.º 14
0
        public List <GridPos> JPSPlus(JumpPointParam JumpPointParameters, GridPos cell1, GridPos cell2)
        {
            List <GridPos> lpath = new List <GridPos>();

            if (JumpPointParameters != null)
            {
                JumpPointParameters.Reset(cell1, cell2);
                List <GridPos> resultPathList = JumpPointFinder.FindPath(JumpPointParameters);
                lpath = JumpPointFinder.GetFullPath(resultPathList);
            }
            return(lpath);
        }
Exemplo n.º 15
0
        private void Load(string fileName)
        {
            if (!File.Exists(fileName))
            {
                Logger.Error("path file do not exit. {0}", fileName);
                return;
            }

            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            int        nSeek      = 0;

            //先从文件头读取地图的长和宽
            byte[] byteLen = new byte[Marshal.SizeOf(typeof(int))];
            fileStream.Seek(nSeek, SeekOrigin.Begin);
            fileStream.Read(byteLen, 0, byteLen.Length);
            Height = System.BitConverter.ToInt32(byteLen, 0);
            nSeek += byteLen.Length;

            byte[] byteWid = new byte[Marshal.SizeOf(typeof(int))];
            fileStream.Seek(nSeek, SeekOrigin.Begin);
            fileStream.Read(byteWid, 0, byteWid.Length);
            Width  = System.BitConverter.ToInt32(byteWid, 0);
            nSeek += byteWid.Length;

            int nReadLen = Marshal.SizeOf(typeof(ObstacleItem));

            byte[] read = new byte[nReadLen];

            mSearchGrid = new StaticGrid(Width * 2 + 1, Height * 2 + 1);

            byte[][] mat = new byte[Width * 2 + 1][];

            for (int i = 0; i < Width * 2 + 1; i++)
            {
                mat[i] = new byte[Height * 2 + 1];
            }

            for (int i = 0; i < (Height * 2 + 1) * (Width * 2 + 1); ++i)
            {
                fileStream.Seek(nSeek, SeekOrigin.Begin);
                fileStream.Read(read, 0, nReadLen);
                nSeek += nReadLen;
                ObstacleItem info = Byte2Struct(read);

                mat[(int)(info.Fx * 2)][(int)(info.Fy * 2)] = (byte)info.Value;
            }

            mSearchGrid.Reset(mat);

            mParam = new JumpPointParam(mSearchGrid, new GridPos(0, 0), new GridPos(0, 0), true, true, false,
                                        HeuristicMode.MANHATTAN);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Keep in mind this method returns the start end and turn points of the path, and not all movement steps.
        /// </summary>
        private List <GridPos> FindPath(int fromX, int fromZ, int toX, int toZ)
        {
            JumpPointParam jpParam = GetJumpPointParam();

            GridPos from = new GridPos(fromX, fromZ);
            GridPos to   = new GridPos(toX, toZ);

            jpParam.Reset(from, to);

            List <GridPos> routeFound = JumpPointFinder.FindPath(jpParam);

            return(routeFound);
        }
Exemplo n.º 17
0
 public List<GridPos> findPath(BaseGrid grid, DiagonalMovement move, GridPos startPos, GridPos endPos){
     JumpPointParam jpParam = new JumpPointParam(
         grid, 
         startPos, 
         endPos, 
         true,
         move, 
         HeuristicMode.EUCLIDEAN
     );
     List<GridPos> result = JumpPointFinder.FindPath(jpParam); 
     if (debug) Console.WriteLine("found path");
     return result;
 }
Exemplo n.º 18
0
        public void OkEmptyGridTest()
        {
            GridPos        startPos = new GridPos(10, 10);
            GridPos        endPos   = new GridPos(20, 10);
            JumpPointParam jpParam  = new JumpPointParam(_searchGrid, startPos, endPos);

            List <GridPos> resultPathList = JumpPointFinder.FindPath(jpParam);

            Assert.AreEqual(2, resultPathList.Count);
            Assert.AreEqual(startPos.x, resultPathList.First().x);
            Assert.AreEqual(startPos.y, resultPathList.First().y);
            Assert.AreEqual(endPos.x, resultPathList.Last().x);
            Assert.AreEqual(endPos.y, resultPathList.Last().y);
        }
Exemplo n.º 19
0
    public void identifySuccessors(JumpPointParam iParam, Node iNode)
    {
        List <Node> tOpenList = iParam.openList;
        int         tEndX     = iParam.EndNode.xz;
        int         tEndY     = iParam.EndNode.yz;
        Node        tNeighbor;
        GridPos?    tJumpPoint;
        Node        tJumpNode;
        List <Node> tNeighbors = iNode.neighbours;

        for (int i = 0; i < iNode.neighbours.Count; i++)
        {
            tNeighbor = tNeighbors[i];

            tJumpPoint = jumpLoop(iParam, tNeighbor.xz, tNeighbor.yz, iNode.xz, iNode.yz);

            if (tJumpPoint != null)
            {
                tJumpNode = graph[tJumpPoint.Value.x, tJumpPoint.Value.y];
                if (tJumpNode == null)
                {
                    if (iParam.EndNode.xz == tJumpPoint.Value.x && iParam.EndNode.yz == tJumpPoint.Value.y)
                    {
                        tJumpNode = graph[tJumpPoint.Value.x, tJumpPoint.Value.y];
                    }
                }
                if (tJumpNode.isClosed)
                {
                    continue;
                }

                float tCurNodeToJumpNodeLen = Manhattan(Mathf.Abs(tJumpPoint.Value.x - iNode.xz), Mathf.Abs(tJumpPoint.Value.y - iNode.yz));
                float tStartToJumpNodeLen   = iNode.startToCurNodeLen + tCurNodeToJumpNodeLen;
                if (!tJumpNode.isOpened || tStartToJumpNodeLen < tJumpNode.startToCurNodeLen)
                {
                    tJumpNode.startToCurNodeLen        = tStartToJumpNodeLen;
                    tJumpNode.heuristicCurNodeToEndLen = (tJumpNode.heuristicCurNodeToEndLen == null ? Manhattan(Mathf.Abs(tJumpPoint.Value.x - tEndX), Mathf.Abs(tJumpPoint.Value.y - tEndY)) : tJumpNode.heuristicCurNodeToEndLen);
                    tJumpNode.heuristicStartToEndLen   = tJumpNode.startToCurNodeLen + tJumpNode.heuristicCurNodeToEndLen.Value;
                    tJumpNode.parent = iNode;

                    if (!tJumpNode.isOpened)
                    {
                        tOpenList.Add(tJumpNode);
                        tJumpNode.isOpened = true;
                    }
                }
            }
        }
    }
Exemplo n.º 20
0
        public IEnumerable <Point> FindPath(Point startPos, Point endPos)
        {
            var start = new GridPos(startPos.X, startPos.Y);
            var end   = new GridPos(endPos.X, endPos.Y);

            var param = new JumpPointParam(_staticGrid, start, end, EndNodeUnWalkableTreatment.Allow);

            var listPositions = JumpPointFinder.FindPath(param);

            return(listPositions.Select(z => new Point()
            {
                X = z.x,
                Y = z.y
            }));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Finds a path between 2 position on a map
        /// </summary>
        /// <param name="startPosition">Starting position</param>
        /// <param name="endPosition">Destination</param>
        /// <param name="map">Game map currently being used</param>
        /// <param name="endNodeUnWalkable"></param>
        /// <returns>A list of Vector2 waypoints that the object must traverse to get to its destination</returns>
        internal Stack <Vector2> FindPath(Vector2 startPosition, Vector2 endPosition, ref Map.Map map, EndNodeUnWalkableTreatment endNodeUnWalkable = EndNodeUnWalkableTreatment.DISALLOW)
        {
            if (!Map.Map.IsOnTop(endPosition) || !map.GetCollisionMap().GetWalkabilityGrid().IsWalkableAt(VectorToGridPos(endPosition)))
            {
                return(new Stack <Vector2>());
            }

            var startGridPos = VectorToGridPos(startPosition);
            var endGridPos   = VectorToGridPos(endPosition);

            if (ClearDirectPath(startGridPos.x, startGridPos.y, endGridPos.x, endGridPos.y, ref map))
            {
                var pathVector = new Stack <Vector2>(1);
                pathVector.Push(endPosition);
                return(pathVector);
            }
            else
            {
                if (mJpParam != null)
                {
                    mJpParam.Reset(VectorToGridPos(startPosition), VectorToGridPos(endPosition));
                }
                else
                {
                    mJpParam = new JumpPointParam(map.GetCollisionMap().GetWalkabilityGrid(),
                                                  startGridPos,
                                                  iDiagonalMovement: DiagonalMovement.OnlyWhenNoObstacles,
                                                  iEndPos: endGridPos,
                                                  iAllowEndNodeUnWalkable: endNodeUnWalkable,
                                                  iMode: HeuristicMode.MANHATTAN);
                }

                var pathGrid = JumpPointFinder.FindPath(mJpParam);

                var pathVector = new Stack <Vector2>(pathGrid.Count);

                pathVector.Push(endPosition);


                for (var i = pathGrid.Count - 1; i > 0; i--)
                {
                    var gridPos = GridPosToVector2(pathGrid[i]);
                    pathVector.Push(gridPos);
                }

                return(pathVector);
            }
        }
Exemplo n.º 22
0
    public List <Vector3> FindPath(GridPos startPos, GridPos endPos)
    {
        BaseGrid searchGrid = CreateMovableGrid();

        JumpPointParam jpParam = new JumpPointParam(searchGrid, startPos, endPos, EndNodeUnWalkableTreatment.ALLOW, DiagonalMovement.Always, HeuristicMode.MANHATTAN);

        List <GridPos> resultPathList = JumpPointFinder.FindPath(jpParam);
        List <Vector3> worldPath      = new List <Vector3>();

        for (int i = 0; i < resultPathList.Count; i++)
        {
            worldPath.Add(GridPosToWorld(resultPathList[i].x, resultPathList[i].y));
        }

        return(worldPath);
    }
Exemplo n.º 23
0
        public void OkObstacleTest()
        {
            _searchGrid.SetWalkableAt(15, 10, false);

            GridPos        startPos = new GridPos(10, 10);
            GridPos        endPos   = new GridPos(20, 10);
            JumpPointParam jpParam  = new JumpPointParam(_searchGrid, startPos, endPos);

            List <GridPos> resultPathList = JumpPointFinder.FindPath(jpParam);

            Assert.Greater(resultPathList.Count, 2);
            Assert.AreEqual(startPos.x, resultPathList.First().x);
            Assert.AreEqual(startPos.y, resultPathList.First().y);
            Assert.AreEqual(endPos.x, resultPathList.Last().x);
            Assert.AreEqual(endPos.y, resultPathList.Last().y);
        }
Exemplo n.º 24
0
        public SearchGridForm()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            m_resultBox      = new List <ResultBox>();
            this.Width       = (width + 1) * 20;
            this.Height      = (height + 1) * 20 + 100;
            this.MaximumSize = new Size(this.Width, this.Height);
            this.MaximizeBox = false;


            m_rectangles = new GridBox[width][];
            for (int widthTrav = 0; widthTrav < width; widthTrav++)
            {
                m_rectangles[widthTrav] = new GridBox[height];
                for (int heightTrav = 0; heightTrav < height; heightTrav++)
                {
                    if (widthTrav == (width / 3) && heightTrav == (height / 2))
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Start);
                    }
                    else if (widthTrav == 41 && heightTrav == (height / 2))
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.End);
                    }
                    else
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Normal);
                    }
                }
            }
            cbbJumpType.Items.Add("Always");
            cbbJumpType.Items.Add("Never");
            cbbJumpType.Items.Add("IfAtLeastOneWalkable");
            cbbJumpType.Items.Add("OnlyWhenNoObstacles");
            cbbJumpType.SelectedIndex = 0;

            m_resultLine = new List <GridLine>();

            searchGrid = new StaticGrid(width, height);
            // searchGrid = new DynamicGrid();
            //searchGrid = new DynamicGridWPool(SingletonHolder<NodePool>.Instance);

            jumpParam = new JumpPointParam(searchGrid, true, (DiagonalMovement)cbbJumpType.SelectedIndex, HeuristicMode.EUCLIDEAN);//new JumpPointParam(searchGrid, startPos, endPos, cbCrossCorners.Checked, HeuristicMode.EUCLIDEANSQR);
            jumpParam.UseRecursive = cbUseRecursive.Checked;
        }
Exemplo n.º 25
0
        public static List <GridPos> GetPath(Point2D start, Point2D end)
        {
            BaseGrid searchGrid = new StaticGrid(gridSize, gridSize, MovableMatrix);

            var startGridPos = GetGridPosByPoint2d(start, gridStep);
            var endGridPos   = GetGridPosByPoint2d(end, gridStep);


            JumpPointParam jpParam = new JumpPointParam(searchGrid, startGridPos, endGridPos);
            var            result  = JumpPointFinder.FindPath(jpParam);

            result = JumpPointFinder.GetFullPath(result);

            DrawPath(result, gridStep);

            return(result);
        }
Exemplo n.º 26
0
        public void ErrorUnrecheableTest()
        {
            _searchGrid.SetWalkableAt(19, 9, false);
            _searchGrid.SetWalkableAt(20, 9, false);
            _searchGrid.SetWalkableAt(21, 9, false);
            _searchGrid.SetWalkableAt(21, 10, false);
            _searchGrid.SetWalkableAt(21, 11, false);
            _searchGrid.SetWalkableAt(20, 11, false);
            _searchGrid.SetWalkableAt(19, 11, false);
            _searchGrid.SetWalkableAt(19, 10, false);

            GridPos        startPos = new GridPos(10, 10);
            GridPos        endPos   = new GridPos(20, 10);
            JumpPointParam jpParam  = new JumpPointParam(_searchGrid, startPos, endPos);

            List <GridPos> resultPathList = JumpPointFinder.FindPath(jpParam);

            Assert.IsEmpty(resultPathList);
        }
Exemplo n.º 27
0
        private JumpPointParam GetJumpPointParam()
        {
            if (_cachedJpParam == null)
            {
                BaseGrid searchGrid = new StaticGrid(WorldController.instance.Width, WorldController.instance.Height);

                for (int x = 0; x < WorldController.instance.Width; x++)
                {
                    for (int z = 0; z < WorldController.instance.Height; z++)
                    {
                        searchGrid.SetWalkableAt(x, z, true);
                    }
                }

                _cachedJpParam = new JumpPointParam(searchGrid); // Cant configure it to not allow diagonally moving, has to be enforced by us
            }

            return(_cachedJpParam);
        }
Exemplo n.º 28
0
 private void monsterUpdate(object sender, MonsterUpdateEventArgs e)
 {
     PlayerSeen = canSeePlayer(e.engine.map.mGrid, e.playerPos);
     if (moves.Count == 0)
     {
         if (PlayerSeen)
         {
             JumpPointParam jParam = new JumpPointParam(e.engine.searchgrid, false, false);
             jParam.Reset(new GridPos(pos.X, pos.Y), new GridPos(e.playerPos.X, e.playerPos.Y));
             List <GridPos> resultPathList = JumpPointFinder.FindPath(jParam);
             resultPathList = JumpPointFinder.GetFullPath(resultPathList);
             if (moves.Count != 0)
             {
                 moves.Clear();
             }
             for (int i = 0; i < resultPathList.Count; i++)
             {
                 moves.Enqueue(new Vector2(resultPathList[i].x, resultPathList[i].y));
             }
         }
     }
     if (moves.Count != 0)
     {
         var dxdy = e.engine.map.getDxDy(pos, moves.Dequeue());
         if (!e.engine.checkEntity(pos, e.playerPos, dxdy.X, dxdy.Y))
         {
             move(dxdy.X, dxdy.Y);
         }
     }
     if (PlayerSeen == false)
     {
         Vector2 a = rndMoves[rnd.Next(rndMoves.Count)];
         if (e.engine.map.canMove(pos, a.X, a.Y))
         {
             move(a.X, a.Y);
         }
     }
     if (isPlayerNear(e.playerPos))
     {
         attack(e.engine.player);
     }
 }
Exemplo n.º 29
0
        public SearchGridForm()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            m_resultBox      = new List <ResultBox>();
            this.Width       = (width + 1) * 20;
            this.Height      = (height + 1) * 20 + 100;
            this.MaximumSize = new Size(this.Width, this.Height);
            this.MaximizeBox = false;


            m_rectangles = new GridBox[width][];
            for (int widthTrav = 0; widthTrav < width; widthTrav++)
            {
                m_rectangles[widthTrav] = new GridBox[height];
                for (int heightTrav = 0; heightTrav < height; heightTrav++)
                {
                    if (widthTrav == (width / 3) && heightTrav == (height / 2))
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Start);
                    }
                    else if (widthTrav == 41 && heightTrav == (height / 2))
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.End);
                    }
                    else
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Normal);
                    }
                }
            }

            m_resultLine = new List <GridLine>();

            searchGrid = new StaticGrid(width, height);
            // searchGrid = new DynamicGrid();
            //searchGrid = new DynamicGridWPool(SingletonHolder<NodePool>.Instance);
            jumpParam = new JumpPointParam(searchGrid, true, cbCrossCorners.Checked, cbCrossAdjacentPoint.Checked, HeuristicMode.EUCLIDEAN);//new JumpPointParam(searchGrid, startPos, endPos, cbCrossCorners.Checked, HeuristicMode.EUCLIDEANSQR);
            jumpParam.UseRecursive = cbUseRecursive.Checked;
        }
Exemplo n.º 30
0
        public SearchGridForm()
        {
            InitializeComponent();
            DoubleBuffered = true;

            resultBox   = new List <ResultBox>();
            Width       = (width + 1) * 20;
            Height      = ((height + 1) * 20) + 100;
            MaximumSize = new Size(Width, Height);
            MaximizeBox = false;

            rectangles = new GridBox[width][];
            for (var x = 0; x < width; x++)
            {
                rectangles[x] = new GridBox[height];
                for (var y = 0; y < height; y++)
                {
                    rectangles[x][y] = x == (width / 3) && y == (height / 2)
                                                ? new GridBox(x * 20, (y * 20) + 50, BoxType.Start)
                                                : x == 41 && y == (height / 2)
                                                        ? new GridBox(x * 20, (y * 20) + 50, BoxType.End)
                                                        : new GridBox(x * 20, (y * 20) + 50, BoxType.Normal);
                }
            }
            _ = cbbJumpType.Items.Add("Always");
            _ = cbbJumpType.Items.Add("Never");
            _ = cbbJumpType.Items.Add("IfAtLeastOneWalkable");
            _ = cbbJumpType.Items.Add("OnlyWhenNoObstacles");
            cbbJumpType.SelectedIndex = 0;

            resultLine = new List <GridLine>();

            searchGrid = new StaticGrid(width, height);
            // searchGrid = new DynamicGrid();
            //searchGrid = new DynamicGridWPool(SingletonHolder<NodePool>.Instance);

            jumpParam = new JumpPointParam(searchGrid, EndNodeUnWalkableTreatment.Allow, (DiagonalMovement)cbbJumpType.SelectedIndex, HeuristicMode.Euclidean)
            {
                CurIterationType = cbUseRecursive.Checked ? IterationType.Recursive : IterationType.Loop
            };            //new JumpPointParam(searchGrid, startPos, endPos, cbCrossCorners.Checked, HeuristicMode.EUCLIDEANSQR);
        }