public void Neighbors_DefaultDirections_IncludeAllClockwiseDirections()
        {
            Vec2            vec2            = new Vec2(5, 5);
            PathfindingGrid grid            = new PathfindingGrid(vec2);
            Vec2            tileCoordinates = new Vec2(3, 3);

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));

            List <GridNode> nodes = new List <GridNode>();

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(2, 2), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(3, 2), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(4, 2), grid));

            nodes.Add(new GridNode(Tiles.Stone, new Vec2(2, 3), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(4, 3), grid));

            nodes.Add(new GridNode(Tiles.Stone, new Vec2(2, 4), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(3, 4), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(4, 4), grid));

            foreach (Direction direction in Direction.Clockwise)
            {
                GridNode neighbor = new GridNode(Tiles.Stone, tileCoordinates + direction, grid);
                Assert.Contains(neighbor, grid.Neighbors(grid[tileCoordinates]));
            }
        }
示例#2
0
 public void Init()
 {
     _grid = new PathfindingGrid(5, 5);
     _grid.Fill(position => new GridNode(Tiles.Stone, position, _grid));
     _grid.FillEdges((position, annotation) => new GridEdge(position, annotation));
     _grid.FillVertices((position) => new GridVertex(position));
 }
        public void FilteredNeighbors_Unconstrained_EightWayNeighbors()
        {
            Vec2            vec2            = new Vec2(5, 5);
            PathfindingGrid grid            = new PathfindingGrid(vec2);
            Vec2            tileCoordinates = new Vec2(3, 3);

            Motility        agentMotility = Motility.Unconstrained | Motility.EightWayNeighbors;
            List <GridNode> nodes         = new List <GridNode>();

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(2, 2), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(3, 2), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(4, 2), grid));

            nodes.Add(new GridNode(Tiles.Stone, new Vec2(2, 3), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(4, 3), grid));

            nodes.Add(new GridNode(Tiles.Stone, new Vec2(2, 4), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(3, 4), grid));
            nodes.Add(new GridNode(Tiles.Stone, new Vec2(4, 4), grid));

            IReadOnlyCollection <GridNode> filteredNeighbors = grid.FilteredNeighbors(grid[tileCoordinates], agentMotility);

            CollectionAssert.AreEquivalent(nodes.AsReadOnly(), filteredNeighbors);
        }
        public void IndexingInt_ReturnsGridNode_IsType()
        {
            Vec2            vec2 = new Vec2(10, 10);
            PathfindingGrid grid = new PathfindingGrid(vec2);

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));
            int int1 = 1;

            Assert.AreEqual(typeof(GridNode), grid[1, 1].GetType());
        }
        public void Neighbors_DefaultDirectionOverload_CountMatches()
        {
            Vec2            vec2            = new Vec2(5, 5);
            PathfindingGrid grid            = new PathfindingGrid(vec2);
            Vec2            tileCoordinates = new Vec2(3, 3);

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));

            Assert.AreEqual(8, grid.Neighbors(grid[tileCoordinates]).Count);
        }
        public void IndexingVec2_SetNode_IsType()
        {
            int             int10 = 10;
            PathfindingGrid grid  = new PathfindingGrid(new Vec2(int10, int10));

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));
            int int1 = 1;

            Assert.AreEqual(typeof(GridNode), grid[int1, int1].GetType());
        }
        public void Neighbors_IntercardinalDirections_IncludeAllIntercardinalDirections()
        {
            Vec2            vec2            = new Vec2(5, 5);
            PathfindingGrid grid            = new PathfindingGrid(vec2);
            Vec2            tileCoordinates = new Vec2(3, 3);

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));

            foreach (Direction direction in Direction.IntercardinalDirections)
            {
                GridNode neighbor = new GridNode(Tiles.Stone, tileCoordinates + direction, grid);
                Assert.Contains(neighbor, grid.Neighbors(grid[tileCoordinates], Direction.IntercardinalDirections));
            }
        }
        public void Neighbors_VariousDirections_CountMatches()
        {
            Vec2            vec2            = new Vec2(5, 5);
            PathfindingGrid grid            = new PathfindingGrid(vec2);
            Vec2            tileCoordinates = new Vec2(3, 3);

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));

            Assert.AreEqual(4, grid.Neighbors(grid[tileCoordinates], Direction.CardinalDirections).Count);
            Assert.AreEqual(8, grid.Neighbors(grid[tileCoordinates], Direction.Clockwise).Count);
            Assert.AreEqual(0, grid.Neighbors(grid[tileCoordinates], new List <Direction> {
                Direction.None
            }).Count);
        }
        public void Fill_SetNode_Equals()
        {
            Vec2            vec2 = new Vec2(2, 2);
            PathfindingGrid grid = new PathfindingGrid(vec2);

            Assert.IsNull(grid[0, 0]);
            Assert.IsNull(grid[0, 1]);
            Assert.IsNull(grid[1, 0]);
            Assert.IsNull(grid[1, 1]);

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));

            Assert.AreEqual(grid[0, 0], new GridNode(Tiles.Stone, Vec2.Zero, grid));
            Assert.AreEqual(grid[0, 1], new GridNode(Tiles.Stone, new Vec2(0, 1), grid));
            Assert.AreEqual(grid[1, 0], new GridNode(Tiles.Stone, new Vec2(1, 0), grid));
            Assert.AreEqual(grid[1, 1], new GridNode(Tiles.Stone, Vec2.One, grid));
        }
        public void FilteredNeighbors_LandMotility_FourWayNeighbors()
        {
            Vec2            vec2            = new Vec2(5, 5);
            PathfindingGrid grid            = new PathfindingGrid(vec2);
            Vec2            tileCoordinates = new Vec2(3, 3);

            Motility        agentMotility = Motility.Land | Motility.FourWayNeighbors;
            List <GridNode> nodes         = new List <GridNode>();

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));
            grid[2, 3] = new GridNode(Tiles.Floor, new Vec2(2, 3), grid);
            grid[3, 4] = new GridNode(Tiles.Floor, new Vec2(3, 4), grid);

            nodes.Add(new GridNode(Tiles.Floor, new Vec2(2, 3), grid));
            nodes.Add(new GridNode(Tiles.Floor, new Vec2(3, 4), grid));

            CollectionAssert.AreEquivalent(nodes.AsReadOnly(), grid.FilteredNeighbors(grid[tileCoordinates], agentMotility));
        }
        public void Fill_SetEdge_Equals()
        {
            Vec2            vec2 = new Vec2(2, 2);
            PathfindingGrid grid = new PathfindingGrid(vec2);

            Assert.IsNull(grid[0, 0, Direction.N]);
            Assert.IsNull(grid[0, 0, Direction.W]);
            Assert.IsNull(grid[0, 0, Direction.E]);
            Assert.IsNull(grid[0, 0, Direction.S]);

            Assert.IsNull(grid[0, 1, Direction.N]);
            Assert.IsNull(grid[0, 1, Direction.W]);
            Assert.IsNull(grid[0, 1, Direction.E]);
            Assert.IsNull(grid[0, 1, Direction.S]);

            Assert.IsNull(grid[1, 0, Direction.N]);
            Assert.IsNull(grid[1, 0, Direction.W]);
            Assert.IsNull(grid[1, 0, Direction.E]);
            Assert.IsNull(grid[1, 0, Direction.S]);

            Assert.IsNull(grid[1, 1, Direction.N]);
            Assert.IsNull(grid[1, 1, Direction.W]);
            Assert.IsNull(grid[1, 1, Direction.E]);
            Assert.IsNull(grid[1, 1, Direction.S]);

            grid.Fill(position => new GridNode(Tiles.Stone, position, grid));
            grid.FillEdges((position, annotation) => new GridEdge(position, annotation));
            //grid.FillVertices((position) => new GridVertex(position));

            Assert.IsNotNull(grid[0, 0, Direction.N]);
            Assert.IsNotNull(grid[0, 0, Direction.W]);
            Assert.IsNotNull(grid[0, 0, Direction.E]);
            Assert.IsNotNull(grid[0, 0, Direction.S]);

            Assert.IsNotNull(grid[0, 1, Direction.N]);
            Assert.IsNotNull(grid[0, 1, Direction.W]);
            Assert.IsNotNull(grid[0, 1, Direction.E]);
            Assert.IsNotNull(grid[0, 1, Direction.S]);

            Assert.IsNotNull(grid[1, 0, Direction.N]);
            Assert.IsNotNull(grid[1, 0, Direction.W]);
            Assert.IsNotNull(grid[1, 0, Direction.E]);
            Assert.IsNotNull(grid[1, 0, Direction.S]);

            Assert.IsNotNull(grid[1, 1, Direction.N]);
            Assert.IsNotNull(grid[1, 1, Direction.W]);
            Assert.IsNotNull(grid[1, 1, Direction.E]);
            Assert.IsNotNull(grid[1, 1, Direction.S]);

            Assert.AreEqual(new GridEdge(Vec2.Zero, Direction.N), grid[0, 0, Direction.N]);
            Assert.AreEqual(new GridEdge(Vec2.Zero, Direction.W), grid[0, 0, Direction.W]);
            Assert.AreEqual(new GridEdge(new Vec2(1, 0), Direction.W), grid[0, 0, Direction.E]);
            Assert.AreEqual(new GridEdge(new Vec2(0, 1), Direction.N), grid[0, 0, Direction.S]);

            Assert.AreEqual(new GridEdge(new Vec2(0, 1), Direction.N), grid[0, 1, Direction.N]);
            Assert.AreEqual(new GridEdge(new Vec2(0, 1), Direction.W), grid[0, 1, Direction.W]);
            Assert.AreEqual(new GridEdge(new Vec2(1, 1), Direction.W), grid[0, 1, Direction.E]);

            var expected = new GridEdge(new Vec2(0, 2), Direction.N);
            var actual   = grid[0, 1, Direction.S];

            Assert.AreEqual(new GridEdge(new Vec2(0, 2), Direction.N), grid[0, 1, Direction.S]);

            Assert.AreEqual(new GridEdge(new Vec2(1, 0), Direction.N), grid[1, 0, Direction.N]);
            Assert.AreEqual(new GridEdge(new Vec2(1, 0), Direction.W), grid[1, 0, Direction.W]);
            Assert.AreEqual(new GridEdge(new Vec2(2, 0), Direction.W), grid[1, 0, Direction.E]);
            Assert.AreEqual(new GridEdge(new Vec2(1, 1), Direction.N), grid[1, 0, Direction.S]);

            Assert.AreEqual(new GridEdge(new Vec2(1, 1), Direction.N), grid[1, 1, Direction.N]);
            Assert.AreEqual(new GridEdge(new Vec2(1, 1), Direction.W), grid[1, 1, Direction.W]);
            Assert.AreEqual(new GridEdge(new Vec2(2, 1), Direction.W), grid[1, 1, Direction.E]);
            Assert.AreEqual(new GridEdge(new Vec2(1, 2), Direction.N), grid[1, 1, Direction.S]);
        }