示例#1
0
        public void StraightPath100Percent()
        {
            string[] inGrid =
            {
                "0.0.0.0.0.0.0",
                ". . . . . . .",
                "0.A#B#C#D#E.0",
                ". . . . . . .",
                "0.0.0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            testRand.Setup(p => p.Next(100, 100)).Returns(100);
            testRand.Setup(p => p.Next(It.IsAny <int>())).Returns(0);

            var pathGen = new SetGridDefaultsStep <IGridPathTestContext> {
                DefaultRatio = new RandRange(100)
            };

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(5));
            Assert.That(floorPlan.GetRoomPlan(0).RoomGen, Is.TypeOf <TestGridRoomGen>());
            Assert.That(floorPlan.GetRoomPlan(1).RoomGen, Is.TypeOf <RoomGenDefault <IGridPathTestContext> >());
            Assert.That(floorPlan.GetRoomPlan(2).RoomGen, Is.TypeOf <RoomGenDefault <IGridPathTestContext> >());
            Assert.That(floorPlan.GetRoomPlan(3).RoomGen, Is.TypeOf <RoomGenDefault <IGridPathTestContext> >());
            Assert.That(floorPlan.GetRoomPlan(4).RoomGen, Is.TypeOf <TestGridRoomGen>());
        }
示例#2
0
        public void PlaceRoom(int roll, int expectedChosen)
        {
            // verify rand is working
            // place on a floor where the first room is immutable
            // place on a floor where the first room is default
            string[] inGrid =
            {
                "0.0.0.0.0.0.0",
                ". . . . . . .",
                "0.A#B#C#D#E.0",
                ". . . . . . .",
                "0.0.0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            GridRoomPlan      roomPlan  = floorPlan.GetRoomPlan(1);

            roomPlan.Components.Set(new TestComponent());
            roomPlan            = floorPlan.GetRoomPlan(3);
            roomPlan.RoomGen    = new RoomGenDefault <IGridPathTestContext>();
            roomPlan.PreferHall = true;

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            // The roll for size
            testRand.Setup(p => p.Next(0, 0)).Returns(0);

            // The roll for choosing room index
            testRand.Setup(p => p.Next(3)).Returns(roll);

            var pathGen = new SetGridSpecialRoomStep <IGridPathTestContext>
            {
                Rooms = new PresetPicker <RoomGen <IGridPathTestContext> >(new RoomGenSquare <IGridPathTestContext>()),
            };

            pathGen.Filters.Add(new RoomFilterComponent(true, new TestComponent()));

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(5));
            for (int ii = 0; ii < 5; ii++)
            {
                if (ii == expectedChosen)
                {
                    Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.TypeOf <RoomGenSquare <IGridPathTestContext> >());
                }
                else
                {
                    Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.Not.TypeOf <RoomGenSquare <IGridPathTestContext> >());
                }
            }
        }
示例#3
0
        public static void CompareFloorPlans(TestGridFloorPlan floorPlan, TestGridFloorPlan compareFloorPlan)
        {
            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(compareFloorPlan.RoomCount));
            for (int ii = 0; ii < floorPlan.RoomCount; ii++)
            {
                GridRoomPlan plan        = floorPlan.GetRoomPlan(ii);
                GridRoomPlan comparePlan = compareFloorPlan.GetRoomPlan(ii);
                Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen));
                Assert.That(plan.Bounds, Is.EqualTo(comparePlan.Bounds));
            }

            // check positions
            Assert.That(floorPlan.PublicRooms, Is.EqualTo(compareFloorPlan.PublicRooms));
            Assert.That(floorPlan.PublicVHalls.Length, Is.EqualTo(compareFloorPlan.PublicVHalls.Length));
            for (int xx = 0; xx < floorPlan.PublicVHalls.Length; xx++)
            {
                Assert.That(floorPlan.PublicVHalls[xx].Length, Is.EqualTo(compareFloorPlan.PublicVHalls[xx].Length));
                for (int yy = 0; yy < floorPlan.PublicVHalls[xx].Length; yy++)
                {
                    Assert.That(floorPlan.PublicVHalls[xx][yy].Gens, Is.EqualTo(compareFloorPlan.PublicVHalls[xx][yy].Gens));
                }
            }

            Assert.That(floorPlan.PublicHHalls.Length, Is.EqualTo(compareFloorPlan.PublicHHalls.Length));
            for (int xx = 0; xx < floorPlan.PublicHHalls.Length; xx++)
            {
                Assert.That(floorPlan.PublicHHalls[xx].Length, Is.EqualTo(compareFloorPlan.PublicHHalls[xx].Length));
                for (int yy = 0; yy < floorPlan.PublicVHalls[xx].Length; yy++)
                {
                    Assert.That(floorPlan.PublicHHalls[xx][yy].Gens, Is.EqualTo(compareFloorPlan.PublicHHalls[xx][yy].Gens));
                }
            }
        }
示例#4
0
        public void PlaceRoomImpossible()
        {
            // verify rand is working
            // place on a floor where the first room is immutable
            // place on a floor where the first room is default
            string[] inGrid =
            {
                "0.0.0.0.0",
                ". . . . .",
                "0.A#B#C.0",
                ". . . . .",
                "0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            GridRoomPlan      roomPlan  = floorPlan.GetRoomPlan(0);

            roomPlan.Immutable = true;
            roomPlan           = floorPlan.GetRoomPlan(1);
            roomPlan.Immutable = true;
            roomPlan           = floorPlan.GetRoomPlan(2);
            roomPlan.Immutable = true;

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            var pathGen = new AddGridSpecialRoomStep <IGridPathTestContext>
            {
                Rooms = new PresetPicker <RoomGen <IGridPathTestContext> >(new RoomGenSquare <IGridPathTestContext>()),
            };

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(3));
            for (int ii = 0; ii < 3; ii++)
            {
                Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.TypeOf <TestGridRoomGen>());
            }
        }