예제 #1
0
        private static void InitFloorToContext(TestFloorPlan floorPlan, Rect rect, Rect[] rooms, Rect[] halls, Tuple <char, char>[] links)
        {
            floorPlan.InitRect(rect);

            // a quick way to set up rooms, halls, and connections
            // a list of rects for rooms, a list of rects for halls
            for (int ii = 0; ii < rooms.Length; ii++)
            {
                var gen = new TestFloorPlanGen((char)('A' + ii));
                gen.PrepareDraw(rooms[ii]);
                floorPlan.PublicRooms.Add(new FloorRoomPlan(gen, new ComponentCollection()));
            }

            for (int ii = 0; ii < halls.Length; ii++)
            {
                var gen = new TestFloorPlanGen((char)('a' + ii));
                gen.PrepareDraw(halls[ii]);
                floorPlan.PublicHalls.Add(new FloorHallPlan(gen, new ComponentCollection()));
            }

            // and finally a list of tuples that link rooms to rooms and halls to halls
            for (int ii = 0; ii < links.Length; ii++)
            {
                bool           hall1  = links[ii].Item1 >= 'a';
                int            index1 = hall1 ? links[ii].Item1 - 'a' : links[ii].Item1 - 'A';
                bool           hall2  = links[ii].Item2 >= 'a';
                int            index2 = hall2 ? links[ii].Item2 - 'a' : links[ii].Item2 - 'A';
                var            link1  = new RoomHallIndex(index1, hall1);
                var            link2  = new RoomHallIndex(index2, hall2);
                IFloorRoomPlan from1  = floorPlan.GetRoomHall(link1);
                IFloorRoomPlan from2  = floorPlan.GetRoomHall(link2);
                from1.Adjacents.Add(link2);
                from2.Adjacents.Add(link1);
            }
        }
예제 #2
0
        public void PlaceRoomMultiAdjacent()
        {
            // the new room touches adjacents of two sides of the old room
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(3, 1, 2, 2), new Rect(1, 3, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') });
            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 1, 2, 2), new Rect(1, 3, 2, 2), new Rect(3, 3, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('C', 'B'), Tuple.Create('C', 'A') });

            ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D';

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

            var gen = new TestFloorPlanGen('D');

            gen.PrepareDraw(new Rect(3, 3, 2, 2));

            var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);
            var mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object);

            pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false));

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
예제 #3
0
        public void PlaceRoomAllSupport()
        {
            // needs a supporting hall for all sides
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(5, 9, 2, 2), new Rect(1, 5, 2, 2), new Rect(5, 1, 2, 2), new Rect(9, 5, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C'), Tuple.Create('A', 'D'), Tuple.Create('A', 'E') });

            TestFloorPlan compareFloorPlan;

            {
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('E', 'a'),
                    Tuple.Create('E', 'b'),
                    Tuple.Create('E', 'c'),
                    Tuple.Create('E', 'd'),
                    Tuple.Create('a', 'A'),
                    Tuple.Create('b', 'B'),
                    Tuple.Create('c', 'C'),
                    Tuple.Create('d', 'D'),
                };
                compareFloorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(22, 14),
                    new Rect[] { new Rect(5, 9, 2, 2), new Rect(1, 5, 2, 2), new Rect(5, 1, 2, 2), new Rect(9, 5, 2, 2), new Rect(5, 5, 2, 2) },
                    new Rect[] { new Rect(5, 7, 2, 2), new Rect(3, 5, 2, 2), new Rect(5, 3, 2, 2), new Rect(7, 5, 2, 2) },
                    links);
            }

            ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(3)).Identifier = 'E';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(4)).Identifier = 'F';

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

            var gen = new TestFloorPlanGen('F');

            gen.PrepareDraw(new Rect(5, 5, 2, 2));

            var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > > mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            Moq.Language.ISetupSequentialResult <PermissiveRoomGen <IFloorPlanTestContext> > hallSeq = mockHalls.SetupSequence(p => p.Pick(testRand.Object));
            hallSeq = hallSeq.Returns(new TestFloorPlanGen('a'));
            hallSeq = hallSeq.Returns(new TestFloorPlanGen('b'));
            hallSeq = hallSeq.Returns(new TestFloorPlanGen('c'));
            hallSeq = hallSeq.Returns(new TestFloorPlanGen('d'));

            var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object);

            pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false));

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
예제 #4
0
        public void PlaceRoomsOnFloorIntrusiveHalls()
        {
            // place a ring of rooms connected by halls
            string[] inGrid =
            {
                "A.0",
                ". .",
                "A#B",
                ". .",
                "0.B",
            };

            TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5);

            for (int ii = 0; ii < gridPlan.RoomCount; ii++)
            {
                var gen = new TestFloorPlanGen(((TestGridRoomGen)gridPlan.GetRoom(ii)).Identifier)
                {
                    ProposedSize = new Loc(2, 2),
                };

                gridPlan.PublicArrayRooms[ii].RoomGen = gen;
            }

            gridPlan.PublicHHalls[0][1].SetGen(new TestFloorPlanGen('a'));

            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                gridPlan.Size,
                new Rect[] { new Rect(0, 0, 2, 2), new Rect(9, 15, 2, 2) },
                new Rect[] { new Rect(2, 1, 4, 10), new Rect(6, 6, 3, 10) },
                new Tuple <char, char>[] { Tuple.Create('A', 'a'), Tuple.Create('a', 'b'), Tuple.Create('b', 'B') });

            ((TestFloorPlanGen)compareFloorPlan.PublicHalls[1].RoomGen).Identifier = 'a';

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

            Moq.Language.ISetupSequentialResult <int> seq = testRand.SetupSequence(p => p.Next(4));
            seq = seq.Returns(0);
            seq = seq.Returns(3);
            seq = testRand.SetupSequence(p => p.Next(10));
            seq = seq.Returns(0);
            seq = seq.Returns(9);

            var floorPlan = new TestFloorPlan();

            floorPlan.InitSize(gridPlan.Size);

            Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict);

            mockMap.SetupGet(p => p.Rand).Returns(testRand.Object);
            mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan);

            gridPlan.PlaceRoomsOnFloor(mockMap.Object);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
예제 #5
0
        public void AddDisconnectedLateBorder()
        {
            // confirm bottom right corner can be used
            TestFloorPlan floorPlan;
            {
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(20, 20),
                    new Rect[] { },
                    new Rect[] { },
                    new Tuple <char, char>[] { });
            }

            TestFloorPlan compareFloorPlan;
            {
                compareFloorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(20, 20),
                    new Rect[] { new Rect(16, 16, 4, 4) },
                    new Rect[] { },
                    new Tuple <char, char>[] { });
            }

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

            testRand.Setup(p => p.Next(1, 1)).Returns(1);
            testRand.Setup(p => p.Next(0, 17)).Returns(16);

            var roomGen = new TestFloorPlanGen('A')
            {
                ProposedSize = new Loc(4, 4)
            };
            var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            mockRooms.Setup(p => p.Pick(testRand.Object)).Returns(roomGen);

            var pathGen = new AddDisconnectedRoomsStep <IFloorPlanTestContext>(mockRooms.Object)
            {
                Amount = new RandRange(1)
            };

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
예제 #6
0
        public void AddDisconnectedNoCollide()
        {
            // fail via collision
            TestFloorPlan floorPlan;
            {
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(20, 20),
                    new Rect[] { new Rect(4, 4, 16, 16) },
                    new Rect[] { },
                    new Tuple <char, char>[] { });
            }

            TestFloorPlan compareFloorPlan;
            {
                compareFloorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(20, 20),
                    new Rect[] { new Rect(4, 4, 16, 16), new Rect(0, 0, 3, 3) },
                    new Rect[] { },
                    new Tuple <char, char>[] { });
            }

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

            testRand.Setup(p => p.Next(1, 1)).Returns(1);
            testRand.Setup(p => p.Next(0, 18)).Returns(0);

            var roomGen = new TestFloorPlanGen('B')
            {
                ProposedSize = new Loc(3, 3)
            };
            var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            mockRooms.Setup(p => p.Pick(testRand.Object)).Returns(roomGen);

            var pathGen = new AddDisconnectedRoomsStep <IFloorPlanTestContext>(mockRooms.Object)
            {
                Amount = new RandRange(1)
            };

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
예제 #7
0
        public void PlaceRoomOneSupport()
        {
            // needs a supporting hall for one side
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(5, 1, 2, 2), new Rect(5, 9, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') });
            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(5, 1, 2, 2), new Rect(5, 9, 2, 2), new Rect(5, 3, 2, 2) },
                new Rect[] { new Rect(5, 5, 2, 4) },
                new Tuple <char, char>[] { Tuple.Create('C', 'A'), Tuple.Create('C', 'a'), Tuple.Create('a', 'B') });

            ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D';

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

            var gen = new TestFloorPlanGen('D');

            gen.PrepareDraw(new Rect(5, 3, 2, 2));

            var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > > mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            mockHalls.Setup(p => p.Pick(testRand.Object)).Returns(new TestFloorPlanGen('a'));

            var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object);

            pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false));

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
예제 #8
0
        public void PlaceRoomsOnFloorDefault()
        {
            // place a line of rooms with one default
            string[] inGrid =
            {
                "A#B#C",
                ". . .",
                "0.0.0",
            };

            TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5);

            {
                var gen = new TestFloorPlanGen('A')
                {
                    ProposedSize = new Loc(5, 5)
                };
                gridPlan.PublicArrayRooms[0].RoomGen = gen;
            }

            {
                gridPlan.PublicArrayRooms[1].RoomGen    = new RoomGenDefault <IFloorPlanTestContext>();
                gridPlan.PublicArrayRooms[1].PreferHall = true;
            }

            {
                var gen = new TestFloorPlanGen('B')
                {
                    ProposedSize = new Loc(5, 5)
                };
                gridPlan.PublicArrayRooms[2].RoomGen = gen;
            }

            gridPlan.PublicHHalls[0][0].SetGen(new TestFloorPlanGen('b'));
            gridPlan.PublicHHalls[1][0].SetGen(new TestFloorPlanGen('c'));

            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                gridPlan.Size,
                new Rect[] { new Rect(0, 0, 5, 5), new Rect(12, 0, 5, 5) },
                new Rect[] { new Rect(6, 0, 1, 1), new Rect(5, 0, 1, 5), new Rect(7, 0, 5, 5) },
                new Tuple <char, char>[] { Tuple.Create('A', 'b'), Tuple.Create('b', 'a'), Tuple.Create('a', 'c'), Tuple.Create('c', 'B') });

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

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

            var floorPlan = new TestFloorPlan();

            floorPlan.InitSize(gridPlan.Size);

            Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict);

            mockMap.SetupGet(p => p.Rand).Returns(testRand.Object);
            mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan);

            gridPlan.PlaceRoomsOnFloor(mockMap.Object);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(compareFloorPlan.RoomCount));
            for (int ii = 0; ii < floorPlan.RoomCount; ii++)
            {
                FloorRoomPlan plan        = floorPlan.PublicRooms[ii];
                FloorRoomPlan comparePlan = compareFloorPlan.PublicRooms[ii];
                Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen));
                Assert.That(plan.Adjacents, Is.EqualTo(comparePlan.Adjacents));
            }

            Assert.That(floorPlan.HallCount, Is.EqualTo(compareFloorPlan.HallCount));
            for (int ii = 0; ii < floorPlan.HallCount; ii++)
            {
                FloorHallPlan plan        = floorPlan.PublicHalls[ii];
                FloorHallPlan comparePlan = compareFloorPlan.PublicHalls[ii];
                if (ii != 0)
                {
                    Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen));
                }
                else
                {
                    // special case for the default
                    Assert.That(plan.RoomGen, Is.TypeOf <RoomGenDefault <IFloorPlanTestContext> >());
                    Assert.That(plan.RoomGen.Draw, Is.EqualTo(comparePlan.RoomGen.Draw));
                }

                Assert.That(plan.Adjacents, Is.EqualTo(comparePlan.Adjacents));
            }
        }
예제 #9
0
        public void PlaceRoomsOnFloorRing()
        {
            // place a ring of rooms connected by halls
            string[] inGrid =
            {
                "A#B",
                "# #",
                "D#C",
            };

            TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5);

            for (int ii = 0; ii < gridPlan.RoomCount; ii++)
            {
                var gen = new TestFloorPlanGen(((TestGridRoomGen)gridPlan.GetRoom(ii)).Identifier)
                {
                    ProposedSize = new Loc(5, 5),
                };
                gridPlan.PublicArrayRooms[ii].RoomGen = gen;
            }

            gridPlan.PublicVHalls[0][0].SetGen(new TestFloorPlanGen('a'));
            gridPlan.PublicVHalls[1][0].SetGen(new TestFloorPlanGen('b'));
            gridPlan.PublicHHalls[0][0].SetGen(new TestFloorPlanGen('c'));
            gridPlan.PublicHHalls[0][1].SetGen(new TestFloorPlanGen('d'));

            TestFloorPlan compareFloorPlan;
            {
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('A', 'a'),
                    Tuple.Create('a', 'D'),
                    Tuple.Create('B', 'b'),
                    Tuple.Create('b', 'C'),
                    Tuple.Create('A', 'c'),
                    Tuple.Create('c', 'B'),
                    Tuple.Create('D', 'd'),
                    Tuple.Create('d', 'C'),
                };
                compareFloorPlan = TestFloorPlan.InitFloorToContext(
                    gridPlan.Size,
                    new Rect[] { new Rect(0, 0, 5, 5), new Rect(6, 0, 5, 5), new Rect(6, 6, 5, 5), new Rect(0, 6, 5, 5) },
                    new Rect[] { new Rect(0, 5, 5, 1), new Rect(6, 5, 5, 1), new Rect(5, 0, 1, 5), new Rect(5, 6, 1, 5) },
                    links);
            }

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

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

            var floorPlan = new TestFloorPlan();

            floorPlan.InitSize(gridPlan.Size);

            Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict);

            mockMap.SetupGet(p => p.Rand).Returns(testRand.Object);
            mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan);

            gridPlan.PlaceRoomsOnFloor(mockMap.Object);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }