Esempio n. 1
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));
        }
Esempio n. 2
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);
        }
Esempio n. 3
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));
        }
Esempio n. 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);
        }
Esempio n. 5
0
        public static TestFloorPlan InitFloorToContext(Rect rect, Rect[] rooms, Rect[] halls, Tuple <char, char>[] links)
        {
            var floorPlan = new TestFloorPlan();

            InitFloorToContext(floorPlan, rect, rooms, halls, links);
            return(floorPlan);
        }
Esempio n. 6
0
        public static TestFloorPlan InitFloorToContext(Loc size, Rect[] rooms, Rect[] halls, Tuple <char, char>[] links)
        {
            var floorPlan = new TestFloorPlan();

            InitFloorToContext(floorPlan, new Rect(Loc.Zero, size), rooms, halls, links);
            return(floorPlan);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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)));
        }
Esempio n. 9
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); });
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        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)));
        }
Esempio n. 14
0
        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)));
        }
Esempio n. 15
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));
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
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);
        }
Esempio n. 20
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);
        }
Esempio n. 21
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)));
        }
Esempio n. 22
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);
        }
Esempio n. 23
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));
        }
Esempio n. 24
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));
        }
Esempio n. 25
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));
        }
Esempio n. 26
0
        public void AddRoomToOutOfBounds(int x, int y)
        {
            // attempt to touch out of bounds
            var floorPlan = new TestFloorPlan();

            floorPlan.InitSize(new Loc(22, 14));
            Mock <TestFloorPlanGen> gen = new Mock <TestFloorPlanGen>(MockBehavior.Loose);

            gen.SetupGet(p => p.Draw).Returns(new Rect(x, y, 2, 3));
            gen.Object.Identifier = 'A';

            // check the rooms
            Assert.Throws <InvalidOperationException>(() => { floorPlan.AddRoom(gen.Object, false); });
        }
Esempio n. 27
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));
        }
Esempio n. 28
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));
        }
Esempio n. 29
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));
        }
Esempio n. 30
0
        [TestCase(2, 2, Dir4.None)]  // joined at right-down diagonal
        public void GetDirAdjacent(int dx, int dy, Dir4 expectedDir)
        {
            // transfers based on location; requires EXACT contact
            Mock <IRoomGen> mockFrom = new Mock <IRoomGen>(MockBehavior.Strict);

            mockFrom.SetupGet(p => p.Draw).Returns(new Rect(0, 0, 2, 2));
            Mock <IRoomGen> mockTo = new Mock <IRoomGen>(MockBehavior.Strict);

            mockTo.SetupGet(p => p.Draw).Returns(new Rect(dx, dy, 2, 2));

            var  testFloorPlan = new TestFloorPlan();
            Dir4 dir           = TestFloorPlan.GetDirAdjacent(mockFrom.Object, mockTo.Object);

            Assert.That(dir, Is.EqualTo(expectedDir));
        }