Exemple #1
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 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]);
        }