Ejemplo n.º 1
0
        private void RunSearch()
        {
            var grid = new PathfindingGrid(GridWidth, GridHeight, Allocator.Persistent);

            for (var i = 0; i < Cells.Length; ++i)
            {
                var cell = Cells[i];
                grid.SetClearance(cell.GridX, cell.GridY, cell.Clearance);
                grid.SetFlag(cell.GridX, cell.GridY, cell.Capabilities);
            }

            NativeList <int> path = new NativeList <int>(Allocator.Persistent);
            var pathFound         = AStarSearch.TryGetPath(grid,
                                                           SelectedCell1.GridX, SelectedCell1.GridY,
                                                           SelectedCell2.GridX, SelectedCell2.GridY,
                                                           UnitSize, UnitCapabilities,
                                                           Allocator.Persistent, path);

            foreach (var index in path)
            {
                Cells[index].SetCellColor(SelectedColor);
            }

            if (path.IsCreated)
            {
                path.Dispose();
            }

            grid.Dispose();
        }
Ejemplo n.º 2
0
        [Test] //Partial vertical block
        public void PathFoundIsTheShortest_WhenPathIsPartiallyBlocked()
        {
            var grid = new PathfindingGrid(6, 5, Allocator.Persistent);

            SetArea(grid, 6, 5, 1, 1);
            grid.SetClearance(3, 0, 0);
            grid.SetClearance(3, 1, 0);
            grid.SetClearance(3, 2, 0);
            grid.SetClearance(3, 3, 0);

            NativeList <int> resultPath = new NativeList <int>(Allocator.Persistent);
            var pathFound = AStarSearch.TryGetPath(grid,
                                                   2, 0,
                                                   5, 4,
                                                   1, 1, Allocator.Persistent, resultPath);

            Assert.AreEqual(true, pathFound);
            Assert.AreEqual(2, resultPath[0]);
            Assert.AreEqual(8, resultPath[1]);
            Assert.AreEqual(14, resultPath[2]);
            Assert.AreEqual(20, resultPath[3]);
            Assert.AreEqual(27, resultPath[4]);
            Assert.AreEqual(28, resultPath[5]);

            grid.Dispose();
            resultPath.Dispose();
        }
Ejemplo n.º 3
0
        public void GridIsPassableMethodWorksCorrectly(int x, int y, LandscapeType cellType, int cellClearance,
                                                       LandscapeType unitType, int unitySize, bool result)
        {
            var grid = new PathfindingGrid(20, 20, Allocator.Persistent);

            grid.SetFlag(x, y, (long)cellType);
            grid.SetClearance(x, y, cellClearance);
            Assert.AreEqual(result, grid.IsPassable(x, y, (long)unitType, unitySize));
            grid.Dispose();
        }
Ejemplo n.º 4
0
        public void CellFlagIsCorrectlySet()
        {
            const int flag = 20;
            const int X    = 19;
            const int Y    = 19;
            var       grid = new PathfindingGrid(20, 20, Allocator.Persistent);

            grid.SetFlag(X, Y, flag);
            Assert.AreEqual(flag, grid.GetFlag(X, Y));
            grid.Dispose();
        }
Ejemplo n.º 5
0
        public void CellClearanceIsCorrectlySet()
        {
            const int clearance = 20;
            const int X         = 0;
            const int Y         = 1;
            var       grid      = new PathfindingGrid(20, 20, Allocator.Persistent);

            grid.SetClearance(X, Y, clearance);
            Assert.AreEqual(clearance, grid.GetClearance(X, Y));
            grid.Dispose();
        }