Example #1
0
        [TestCase(false, true)]  // hall collision
        public void CheckCollision(bool addRoom, bool addHall)
        {
            List <RoomHallIndex> collidesCompare = new List <RoomHallIndex>();
            List <Rect>          rooms           = new List <Rect>();

            if (addRoom)
            {
                rooms.Add(new Rect(1, 1, 2, 3));
                collidesCompare.Add(new RoomHallIndex(0, false));
            }

            List <Rect> halls = new List <Rect>();

            if (addHall)
            {
                halls.Add(new Rect(4, 1, 3, 2));
                collidesCompare.Add(new RoomHallIndex(0, true));
            }

            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                rooms.ToArray(),
                halls.ToArray(),
                Array.Empty <Tuple <char, char> >());

            List <RoomHallIndex> collides = floorPlan.CheckCollision(new Rect(2, 2, 4, 6));

            Assert.That(collidesCompare, Is.EqualTo(collides));
        }
Example #2
0
        public void IsChokePoint(int index, bool isHall, bool expected)
        {
            /* A-a-B-C
             | |
             |     D-b */
            TestFloorPlan floorPlan;
            {
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('A', 'a'),
                    Tuple.Create('a', 'B'),
                    Tuple.Create('B', 'C'),
                    Tuple.Create('B', 'D'),
                    Tuple.Create('C', 'b'),
                    Tuple.Create('D', 'b'),
                };
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(22, 14),
                    new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty, Rect.Empty },
                    new Rect[] { Rect.Empty, Rect.Empty },
                    links);
            }

            bool result = floorPlan.IsChokePoint(new RoomHallIndex(index, isHall));

            Assert.That(result, Is.EqualTo(expected));
        }
Example #3
0
        public void AddHallCollideExistingHall()
        {
            // add on top of existing hall, no consequences
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                Array.Empty <Rect>(),
                new Rect[] { new Rect(1, 1, 2, 3) },
                Array.Empty <Tuple <char, char> >());

            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                Array.Empty <Rect>(),
                new Rect[] { new Rect(1, 1, 2, 3), new Rect(2, 2, 4, 4) },
                Array.Empty <Tuple <char, char> >());

            var gen = new Mock <TestFloorPlanGen>(MockBehavior.Loose)
            {
                CallBase = true
            };

            gen.SetupGet(p => p.Draw).Returns(new Rect(2, 2, 4, 4));
            gen.Object.Identifier = 'b';

            floorPlan.AddHall(gen.Object);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Example #4
0
        public void EraseRoomHallHall()
        {
            // erase existent rooms in the middle of a list, checking for room consistency
            // and adjacency consistency
            TestFloorPlan floorPlan;
            {
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('a', 'b'),
                    Tuple.Create('b', 'c'),
                    Tuple.Create('c', 'a'),
                    Tuple.Create('A', 'a'),
                    Tuple.Create('B', 'b'),
                    Tuple.Create('C', 'c'),
                };
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(22, 14),
                    new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty },
                    new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty },
                    links);
            }

            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty },
                new Rect[] { Rect.Empty, Rect.Empty },
                new Tuple <char, char>[] { Tuple.Create('b', 'a'), Tuple.Create('A', 'a'), Tuple.Create('C', 'b') });

            ((TestFloorPlanGen)compareFloorPlan.GetRoomHall(new RoomHallIndex(1, true)).RoomGen).Identifier = 'c';

            floorPlan.EraseRoomHall(new RoomHallIndex(1, true));

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Example #5
0
        public void AddRoomCollideExisting(bool hall)
        {
            // add on top of existing room?
            List <Rect> rooms = new List <Rect>();
            List <Rect> halls = new List <Rect>();

            if (!hall)
            {
                rooms.Add(new Rect(1, 1, 2, 3));
            }
            else
            {
                halls.Add(new Rect(1, 1, 2, 3));
            }
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                rooms.ToArray(),
                halls.ToArray(),
                Array.Empty <Tuple <char, char> >());

            var gen = new Mock <TestFloorPlanGen>(MockBehavior.Loose)
            {
                CallBase = true
            };

            gen.SetupGet(p => p.Draw).Returns(new Rect(2, 2, 4, 4));
            gen.Object.Identifier = 'B';

            // check the rooms
            Assert.Throws <InvalidOperationException>(() => { floorPlan.AddRoom(gen.Object, false); });
        }
Example #6
0
        public void AddHall()
        {
            // add to empty space
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                Array.Empty <Rect>(),
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                Array.Empty <Rect>(),
                new Rect[] { new Rect(1, 1, 2, 3) },
                Array.Empty <Tuple <char, char> >());

            var gen = new Mock <TestFloorPlanGen>(MockBehavior.Loose)
            {
                CallBase = true
            };

            gen.SetupGet(p => p.Draw).Returns(new Rect(1, 1, 2, 3));
            gen.Object.Identifier = 'a';
            floorPlan.AddHall(gen.Object);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
        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);
        }
Example #8
0
        public void AddRoomToExisting()
        {
            // add with adjacents
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(1, 1, 2, 3) },
                new Rect[] { new Rect(6, 1, 3, 3) },
                Array.Empty <Tuple <char, char> >());

            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(1, 1, 2, 3), new Rect(3, 2, 3, 5) },
                new Rect[] { new Rect(6, 1, 3, 3) },
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('a', 'B') });

            var gen = new Mock <TestFloorPlanGen>(MockBehavior.Loose)
            {
                CallBase = true
            };

            gen.SetupGet(p => p.Draw).Returns(new Rect(3, 2, 3, 5));
            gen.Object.Identifier = 'B';

            floorPlan.AddRoom(gen.Object, false, new RoomHallIndex(0, false), new RoomHallIndex(0, true));

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
        public void GetSupportRect(int x, int y, Dir4 dir, int expectX, int expectY, int expectW, int expectH)
        {
            // the adjacent tile lines up perfectly
            // 2x2 rooms here
            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') });

            IRoomGen oldGen = floorPlan.GetRoom(0);

            Mock <IRoomGen> mockTo = new Mock <IRoomGen>(MockBehavior.Strict);

            mockTo.SetupGet(p => p.Draw).Returns(new Rect(x, y, 2, 2));

            var indexLookup = new Dictionary <Dir4, int> {
                { Dir4.Down, 1 }, { Dir4.Left, 2 }, { Dir4.Up, 3 }, { Dir4.Right, 4 }
            };
            var adjacentsInDir = new List <RoomHallIndex> {
                new RoomHallIndex(indexLookup[dir], false)
            };

            Rect rect = AddSpecialRoomTestStep.GetSupportRect(floorPlan, oldGen, mockTo.Object, dir, adjacentsInDir);

            Assert.That(rect, Is.EqualTo(new Rect(expectX, expectY, expectW, expectH)));
        }
        public void GetSupportRectMultiple()
        {
            // the adjacent tile crosses past the border
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(3, 9, 2, 2), new Rect(7, 9, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') });

            IRoomGen oldGen = floorPlan.GetRoom(0);

            Mock <IRoomGen> mockTo = new Mock <IRoomGen>(MockBehavior.Strict);

            mockTo.SetupGet(p => p.Draw).Returns(new Rect(5, 3, 2, 2));

            var adjacentsInDir = new List <RoomHallIndex>
            {
                new RoomHallIndex(1, false),
                new RoomHallIndex(2, false),
            };

            Rect rect = AddSpecialRoomTestStep.GetSupportRect(floorPlan, oldGen, mockTo.Object, Dir4.Down, adjacentsInDir);

            Assert.That(rect, Is.EqualTo(new Rect(3, 5, 6, 4)));
        }
Example #11
0
        public void GetRoomToConnectRetracted(bool retractLeft, bool retractRight, int rectX, int rectW)
        {
            List <Rect> rooms = new List <Rect>
            {
                new Rect(4, 4, 3, 2),
                new Rect(4, 10, 2, 2),
            };

            if (retractLeft)
            {
                rooms.Add(new Rect(2, 7, 2, 2));
            }
            if (retractRight)
            {
                rooms.Add(new Rect(7, 7, 2, 2));
            }
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                rooms.ToArray(),
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            var nodeResult = ConnectTestStep.GetRoomToConnect(floorPlan, new RoomHallIndex(0, false), Dir4.Down);

            Assert.That(nodeResult.HasValue, Is.True);
            var node = nodeResult.Value;

            Assert.That(node.From, Is.EqualTo(new RoomHallIndex(0, false)));
            Assert.That(node.To, Is.EqualTo(new RoomHallIndex(1, false)));
            Assert.That(node.Connector, Is.EqualTo(new Rect(rectX, 6, rectW, 4)));
        }
Example #12
0
        public void GetDistanceBranchRoute()
        {
            // only hall adjacent

            /* A-D-E
            | |
            |  B-C   */
            TestFloorPlan floorPlan;
            {
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('A', 'B'),
                    Tuple.Create('B', 'C'),
                    Tuple.Create('C', 'D'),
                    Tuple.Create('D', 'E'),
                    Tuple.Create('A', 'D'),
                };
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(22, 14),
                    new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty, Rect.Empty, Rect.Empty },
                    Array.Empty <Rect>(),
                    links);
            }

            int distance = floorPlan.GetDistance(new RoomHallIndex(0, false), new RoomHallIndex(4, false));

            Assert.That(distance, Is.EqualTo(2));
        }
Example #13
0
        public void ConnectFail()
        {
            // A-B-C-D-E
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 2, 2), new Rect(5, 3, 2, 2), new Rect(7, 3, 2, 2), new Rect(9, 3, 2, 2), new Rect(11, 3, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('B', 'C'), Tuple.Create('C', 'D'), Tuple.Create('D', 'E') });
            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 2, 2), new Rect(5, 3, 2, 2), new Rect(7, 3, 2, 2), new Rect(9, 3, 2, 2), new Rect(11, 3, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('B', 'C'), Tuple.Create('C', 'D'), Tuple.Create('D', 'E') });

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

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

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

            var pathGen = new ConnectBranchTestStep(mockHalls.Object);

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
        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);
        }
Example #15
0
        public void ConnectOther()
        {
            /* A D
             * B-CE */
            TestFloorPlan floorPlan;
            {
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('A', 'B'),
                    Tuple.Create('B', 'a'),
                    Tuple.Create('a', 'C'),
                    Tuple.Create('C', 'D'),
                    Tuple.Create('C', 'E'),
                };
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(22, 14),
                    new Rect[] { new Rect(3, 3, 2, 2), new Rect(3, 5, 2, 3), new Rect(7, 5, 2, 3), new Rect(7, 3, 2, 2), new Rect(9, 6, 2, 2) },
                    new Rect[] { new Rect(5, 6, 2, 2) },
                    links);
            }

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

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

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

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

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

            var pathGen = new ConnectBranchTestStep(mockHalls.Object)
            {
                ConnectPercent = 100
            };

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Example #16
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);
        }
Example #17
0
        public void GetPossibleExpansionsWeighted()
        {
            /* A F
             * B E
             * C-DG */
            TestFloorPlan floorPlan;
            {
                Rect[] rooms = new Rect[]
                {
                    new Rect(3, 1, 2, 2),
                    new Rect(3, 3, 2, 2),
                    new Rect(3, 5, 2, 3),
                    new Rect(7, 5, 2, 3),
                    new Rect(7, 3, 2, 2),
                    new Rect(7, 1, 2, 2),
                    new Rect(9, 6, 2, 2),
                };
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('A', 'B'),
                    Tuple.Create('B', 'C'),
                    Tuple.Create('C', 'a'),
                    Tuple.Create('a', 'D'),
                    Tuple.Create('D', 'E'),
                    Tuple.Create('E', 'F'),
                    Tuple.Create('D', 'G'),
                };
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(22, 14),
                    rooms,
                    new Rect[] { new Rect(5, 6, 2, 2) },
                    links);
            }

            var candList = new List <RoomHallIndex>
            {
                new RoomHallIndex(0, false),
                new RoomHallIndex(1, false),
                new RoomHallIndex(2, false),
            };

            var nodes = ConnectTestStep.GetPossibleExpansions(floorPlan, candList);

            Assert.That(nodes.Count, Is.EqualTo(2));
            Assert.That(nodes.GetSpawnRate(0), Is.EqualTo(6));
            Assert.That(nodes.GetSpawn(0).From, Is.EqualTo(new RoomHallIndex(0, false)));
            Assert.That(nodes.GetSpawn(0).To, Is.EqualTo(new RoomHallIndex(5, false)));
            Assert.That(nodes.GetSpawn(0).Connector, Is.EqualTo(new Rect(5, 1, 2, 2)));
            Assert.That(nodes.GetSpawnRate(1), Is.EqualTo(4));
            Assert.That(nodes.GetSpawn(1).From, Is.EqualTo(new RoomHallIndex(1, false)));
            Assert.That(nodes.GetSpawn(1).To, Is.EqualTo(new RoomHallIndex(4, false)));
            Assert.That(nodes.GetSpawn(1).Connector, Is.EqualTo(new Rect(5, 3, 2, 2)));
        }
Example #18
0
        public void GetRoomToConnectNothingThere()
        {
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 2, 2) },
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            var node = ConnectTestStep.GetRoomToConnect(floorPlan, new RoomHallIndex(0, false), Dir4.Down);

            Assert.That(node.HasValue, Is.False);
        }
Example #19
0
        public void GetRoomToConnectRetractedTooMuch()
        {
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(4, 4, 2, 2), new Rect(4, 10, 2, 2), new Rect(2, 7, 2, 2), new Rect(6, 7, 2, 2) },
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            var nodeResult = ConnectTestStep.GetRoomToConnect(floorPlan, new RoomHallIndex(0, false), Dir4.Down);

            Assert.That(nodeResult.HasValue, Is.False);
        }
Example #20
0
        public void IsChokePointIsolated()
        {
            // A-B C
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B') });

            bool result = floorPlan.IsChokePoint(new RoomHallIndex(0, false));

            Assert.That(result, Is.EqualTo(false));
        }
Example #21
0
        public void IsChokePointSingle()
        {
            // A
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { Rect.Empty },
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            bool result = floorPlan.IsChokePoint(new RoomHallIndex(0, false));

            Assert.That(result, Is.EqualTo(false));
        }
Example #22
0
        public void GetBranchArmsT()
        {
            TestFloorPlan floorPlan;
            {
                Rect[] rooms = new Rect[]
                {
                    new Rect(3, 7, 2, 2),
                    new Rect(3, 5, 2, 2),
                    new Rect(3, 3, 2, 2),
                    new Rect(3, 9, 2, 2),
                    new Rect(3, 11, 2, 2),
                    new Rect(5, 7, 2, 2),
                    new Rect(7, 7, 2, 2),
                };
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('A', 'B'),
                    Tuple.Create('B', 'C'),
                    Tuple.Create('A', 'D'),
                    Tuple.Create('D', 'E'),
                    Tuple.Create('A', 'F'),
                    Tuple.Create('F', 'G'),
                };
                floorPlan = TestFloorPlan.InitFloorToContext(new Loc(22, 14), rooms, Array.Empty <Rect>(), links);
            }

            var expectedArms = new List <List <RoomHallIndex> >();
            var arm          = new List <RoomHallIndex>
            {
                new RoomHallIndex(2, false),
                new RoomHallIndex(1, false),
            };

            expectedArms.Add(arm);
            arm = new List <RoomHallIndex>
            {
                new RoomHallIndex(4, false),
                new RoomHallIndex(3, false),
            };
            expectedArms.Add(arm);
            arm = new List <RoomHallIndex>
            {
                new RoomHallIndex(6, false),
                new RoomHallIndex(5, false),
            };
            expectedArms.Add(arm);

            List <List <RoomHallIndex> > arms = ConnectBranchTestStep.GetBranchArms(floorPlan);

            Assert.That(arms, Is.EqualTo(expectedArms));
        }
Example #23
0
        public void GetDistanceOneLine()
        {
            // only hall adjacent
            // A-a-B
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { Rect.Empty, Rect.Empty },
                new Rect[] { Rect.Empty },
                new Tuple <char, char>[] { Tuple.Create('A', 'a'), Tuple.Create('a', 'B') });

            int distance = floorPlan.GetDistance(new RoomHallIndex(0, false), new RoomHallIndex(1, false));

            Assert.That(distance, Is.EqualTo(2));
        }
Example #24
0
        public void GetDistanceSame()
        {
            // same start and end
            // A-B
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { Rect.Empty, Rect.Empty },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B') });

            int distance = floorPlan.GetDistance(new RoomHallIndex(0, false), new RoomHallIndex(0, false));

            Assert.That(distance, Is.EqualTo(0));
        }
Example #25
0
        public void GetBranchArmsSingle()
        {
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 2, 2) },
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            List <List <RoomHallIndex> > expectedArms = new List <List <RoomHallIndex> >();

            List <List <RoomHallIndex> > arms = ConnectBranchTestStep.GetBranchArms(floorPlan);

            Assert.That(arms, Is.EqualTo(expectedArms));
        }
Example #26
0
        public void GetAdjacentRoomsNone()
        {
            // no adjacents
            // A B a
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { Rect.Empty, Rect.Empty },
                new Rect[] { Rect.Empty },
                Array.Empty <Tuple <char, char> >());

            List <int> adjacentRooms = floorPlan.GetAdjacentRooms(0);
            List <int> expectedRooms = new List <int>();

            Assert.That(adjacentRooms, Is.EqualTo(expectedRooms));
        }
Example #27
0
        public void GetAdjacentRoomsOneHall()
        {
            // only hall adjacent
            // A-a-b
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { Rect.Empty },
                new Rect[] { Rect.Empty, Rect.Empty },
                new Tuple <char, char>[] { Tuple.Create('A', 'a'), Tuple.Create('a', 'b') });

            List <int> adjacentRooms = floorPlan.GetAdjacentRooms(0);
            List <int> expectedRooms = new List <int>();

            Assert.That(adjacentRooms, Is.EqualTo(expectedRooms));
        }
Example #28
0
        public void GetPossibleExpansionsAll()
        {
            /*     A B
            *
            *
            *
            *  C   D     E
            |
            |  F   a-G   H
            |
            |
            |      I J     */
            // go through and refuse all GetRoomToConnect calls
            // measure the GetRoomToConnect Calls
            TestFloorPlan floorPlan;
            {
                Rect[] rooms = new Rect[]
                {
                    new Rect(5, 1, 1, 2),
                    new Rect(7, 1, 2, 2),
                    new Rect(1, 5, 2, 1),
                    new Rect(5, 5, 2, 2),
                    new Rect(11, 5, 2, 1),
                    new Rect(1, 7, 2, 1),
                    new Rect(7, 7, 2, 2),
                    new Rect(11, 7, 2, 1),
                    new Rect(5, 11, 1, 2),
                    new Rect(7, 11, 1, 2),
                };
                floorPlan = TestFloorPlan.InitFloorToContext(
                    new Loc(22, 14),
                    rooms,
                    new Rect[] { new Rect(5, 7, 2, 2) },
                    new Tuple <char, char>[] { Tuple.Create('D', 'a'), Tuple.Create('a', 'G') });
            }

            var candList = new List <RoomHallIndex>
            {
                new RoomHallIndex(3, false),
                new RoomHallIndex(0, true),
                new RoomHallIndex(6, false),
            };

            var nodes = ConnectTestStep.GetPossibleExpansions(floorPlan, candList);

            Assert.That(nodes.Count, Is.EqualTo(8));
        }
Example #29
0
        public void GetRoomToConnectBlocked(int blockX, int blockY, Dir4 dir, int rectX, int rectY, int rectW, int rectH)
        {
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(4, 4, 2, 2), new Rect(blockX, blockY, 2, 2) },
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            var nodeResult = ConnectTestStep.GetRoomToConnect(floorPlan, new RoomHallIndex(0, false), dir);

            Assert.That(nodeResult.HasValue, Is.True);
            var node = nodeResult.Value;

            Assert.That(node.From, Is.EqualTo(new RoomHallIndex(0, false)));
            Assert.That(node.To, Is.EqualTo(new RoomHallIndex(1, false)));
            Assert.That(node.Connector, Is.EqualTo(new Rect(rectX, rectY, rectW, rectH)));
        }
Example #30
0
        public void GetPossibleExpansionsOne()
        {
            // two isolated rooms
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 2, 2), new Rect(3, 9, 2, 2) },
                Array.Empty <Rect>(),
                Array.Empty <Tuple <char, char> >());

            var candList = new List <RoomHallIndex> {
                new RoomHallIndex(0, false)
            };
            var nodes = ConnectTestStep.GetPossibleExpansions(floorPlan, candList);

            Assert.That(nodes.Count, Is.EqualTo(1));
            Assert.That(nodes.GetSpawn(0).From, Is.EqualTo(new RoomHallIndex(0, false)));
            Assert.That(nodes.GetSpawn(0).To, Is.EqualTo(new RoomHallIndex(1, false)));
            Assert.That(nodes.GetSpawn(0).Connector, Is.EqualTo(new Rect(3, 5, 2, 4)));
        }