public void SetHallToNull()
        {
            // set existing hall to null
            string[] inGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.0#0.0",
                ". . . .",
                "0.0.0.0",
            };

            string[] outGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);

            floorPlan.SetHall(new LocRay4(1, 1, Dir4.Right), null);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Exemple #2
0
        public void AddRoomToEmptySpace()
        {
            // add to empty space
            string[] inGrid =
            {
                "0.0.0",
                ". . .",
                "0.0.0",
            };

            string[] outGrid =
            {
                "0.A.0",
                ". . .",
                "0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            var gen = new TestGridRoomGen('A');

            floorPlan.AddRoom(new Rect(1, 0, 1, 1), gen, new ComponentCollection());
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
        public void CreatePathWrongDimensions(int vwidth, int vheight, int hwidth, int hheight)
        {
            string[] inGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
            };

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

            var pathGen = new GridPathSpecific <IGridPathTestContext>
            {
                SpecificVHalls = new PermissiveRoomGen <IGridPathTestContext> [vwidth][],
            };

            for (int ii = 0; ii < vwidth; ii++)
            {
                pathGen.SpecificVHalls[ii] = new PermissiveRoomGen <IGridPathTestContext> [vheight];
            }
            pathGen.SpecificHHalls = new PermissiveRoomGen <IGridPathTestContext> [hwidth][];
            for (int ii = 0; ii < hwidth; ii++)
            {
                pathGen.SpecificHHalls[ii] = new PermissiveRoomGen <IGridPathTestContext> [hheight];
            }

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);

            Assert.Throws <InvalidOperationException>(() => { pathGen.ApplyToPath(testRand.Object, floorPlan); });
        }
Exemple #4
0
        public void GetHallTouchRangeLargeRoom(Dir4 dir, int tier, int rangeMin, int rangeMax)
        {
            // a room that takes up multiple cells
            string[] inGrid =
            {
                "A.A.0.0",
                ". . . .",
                "A.A.0.0",
                ". . . .",
                "A.A.0.0",
                ". . . .",
                "0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid, 6, 4);
            Mock <IRandom>    testRand  = new Mock <IRandom>(MockBehavior.Strict);
            IRoomGen          testGen   = floorPlan.PublicArrayRooms[0].RoomGen;

            testGen.PrepareSize(testRand.Object, new Loc(5, 10));
            testGen.SetLoc(new Loc(1, 2));
            IntRange bounds        = floorPlan.GetHallTouchRange(testGen, dir, tier);
            IntRange compareBounds = new IntRange(rangeMin, rangeMax);

            Assert.That(bounds, Is.EqualTo(compareBounds));
        }
Exemple #5
0
        public void CreateError()
        {
            string[] inGrid =
            {
                "0",
                ".",
                "0",
            };

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

            var pathGen = new GridPathTwoSides <IGridPathTestContext> {
                GapAxis = Axis4.Horiz
            };

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

            pathGen.GenericHalls = mockHalls.Object;
            Mock <IRandPicker <RoomGen <IGridPathTestContext> > > mockRooms = new Mock <IRandPicker <RoomGen <IGridPathTestContext> > >(MockBehavior.Strict);

            pathGen.GenericRooms = mockRooms.Object;

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);

            Assert.Throws <InvalidOperationException>(() => { pathGen.ApplyToPath(testRand.Object, floorPlan); });
        }
        public void AddBigRoomToEmptySpace()
        {
            // add big room to empty space
            string[] inGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
            };

            string[] outGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.A.A.A",
                ". . . .",
                "0.A.A.A",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            var gen = new TestGridRoomGen('A');

            floorPlan.AddRoom(new Rect(1, 1, 3, 2), gen);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
        public void AddBigRoomToHall(int gridType)
        {
            // add small room on big room
            string[] inGrid = null;

            switch (gridType)
            {
            case 0:
                inGrid = new string[]
                {
                    "0.0.0.0",
                    ". . . .",
                    "0.0#0.0",
                    ". . . .",
                    "0.0.0.0",
                };
                break;

            case 1:
                inGrid = new string[]
                {
                    "0.0.0.0",
                    ". . . .",
                    "0.0.0.0",
                    ". # . .",
                    "0.0.0.0",
                };
                break;

            case 2:
                inGrid = new string[]
                {
                    "0.0.0.0",
                    ". . . .",
                    "0.0.0.0",
                    ". . # .",
                    "0.0.0.0",
                };
                break;

            case 3:
                inGrid = new string[]
                {
                    "0.0.0.0",
                    ". . . .",
                    "0.0.0.0",
                    ". . . .",
                    "0.0#0.0",
                };
                break;

            default:
                throw new Exception("Unexpected Case");
            }

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            var gen = new TestGridRoomGen('A');

            Assert.Throws <InvalidOperationException>(() => { floorPlan.AddRoom(new Rect(1, 1, 2, 2), gen); });
        }
        public void AddBigRoomToSurrounded()
        {
            // add room to a room/hall-ridden floor where halls just barely avoid the room
            string[] inGrid =
            {
                "A#B#C#D",
                "# # # #",
                "E#0.0#F",
                "# . . #",
                "G#0.0#H",
            };

            string[] outGrid =
            {
                "A#B#C#D",
                "# # # #",
                "E#I.I#F",
                "# . . #",
                "G#I.I#H",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            var gen = new TestGridRoomGen('I');

            floorPlan.AddRoom(new Rect(1, 1, 2, 2), gen);

            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Exemple #9
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>());
        }
Exemple #10
0
        public void GetHallTouchRangeLargeRoomMiddle(int fulfill1, int fulfill2, int rangeMin, int rangeMax)
        {
            string[] inGrid =
            {
                "A.A.A.0",
                ". . . .",
                "A.A.A.0",
                ". . . .",
                "0.0.0.0",
            };
            int width = 16;

            bool[] fulfillable = new bool[width];
            fulfillable[fulfill1] = true;
            fulfillable[fulfill2] = true;

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid, 6, 4);
            Mock <IRandom>    testRand  = new Mock <IRandom>(MockBehavior.Strict);
            TestGridRoomGen   testGen   = (TestGridRoomGen)floorPlan.PublicArrayRooms[0].RoomGen;

            testGen.PrepareSize(testRand.Object, new Loc(width, 6));
            testGen.PrepareFulfillableBorder(Dir4.Down, fulfillable);
            testGen.SetLoc(new Loc(2, 1));
            IntRange bounds        = floorPlan.GetHallTouchRange(testGen, Dir4.Down, 1);
            IntRange compareBounds = new IntRange(rangeMin, rangeMax);

            Assert.That(bounds, Is.EqualTo(compareBounds));
        }
        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);
        }
Exemple #12
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> >());
                }
            }
        }
Exemple #13
0
        public void Comb4Choose3B()
        {
            string[] inGrid =
            {
                "0.0.0.0.0",
                ". . . . .",
                "0.A#C#E#G",
                ". # # # #",
                "0.B.D.F.H",
                ". . . . .",
                "0.0.0.0.0",
            };

            string[] outGrid =
            {
                "0.0.0.0.0",
                ". . . . .",
                "0.A#C#E#G",
                ". # # # #",
                "0.B#D.F#H",
                ". . . . .",
                "0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan        = TestGridFloorPlan.InitGridToContext(inGrid);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

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

            testRand.Setup(p => p.Next(It.IsNotIn <int>(100, 4))).Returns(0);
            testRand.Setup(p => p.Next(4)).Returns(3);
            Moq.Language.ISetupSequentialResult <int> seq = testRand.SetupSequence(p => p.Next(100));
            seq = seq.Returns(0);
            seq = seq.Returns(0);
            seq = seq.Returns(0);
            seq = seq.Returns(99);

            var pathGen = new ConnectGridBranchStep <IGridPathTestContext> {
                ConnectPercent = 50
            };

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

            mockHalls.Setup(p => p.Pick(testRand.Object)).Returns(new TestGridRoomGen());
            pathGen.GenericHalls = mockHalls.Object;

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
        public void AddRoomOutOfRange(int x, int y, int w, int h)
        {
            // out of range
            string[] inGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            var gen = new TestGridRoomGen('A');

            Assert.Throws <ArgumentOutOfRangeException>(() => { floorPlan.AddRoom(new Rect(x, y, w, h), gen); });
        }
        public void AddCrossingRooms()
        {
            // add small room on big room
            string[] inGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.A.A.A",
                ". . . .",
                "0.A.A.A",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            var gen = new TestGridRoomGen('B');

            Assert.Throws <InvalidOperationException>(() => { floorPlan.AddRoom(new Rect(1, 0, 2, 2), gen); });
        }
        public void GetAdjacentRoomsOneCellAllNearDetached()
        {
            // completely filled for all but the one-cell room, detached
            string[] inGrid =
            {
                "G#D#H",
                "# . #",
                "C.A.E",
                "# . #",
                "F#B#I",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            List <int>        rooms     = floorPlan.GetAdjacentRooms(0);
            List <int>        compare   = new List <int>();

            Assert.That(rooms, Is.EqualTo(compare));
        }
        public void GetAdjacentRoomsOneCellNoneNear()
        {
            // completely lone one-cell room
            string[] inGrid =
            {
                "0.0.0",
                ". . .",
                "0.A.0",
                ". . .",
                "0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            List <int>        rooms     = floorPlan.GetAdjacentRooms(0);
            List <int>        compare   = new List <int>();

            Assert.That(rooms, Is.EqualTo(compare));
        }
Exemple #18
0
        public void Wishbone()
        {
            string[] inGrid =
            {
                "0.C#D#E#F.0",
                ". # . . # .",
                "A#B.0.0.G.0",
                ". # . . . .",
                "0.H.0.0.M.0",
                ". # . . # .",
                "0.I#J#K#L.0",
            };

            string[] outGrid =
            {
                "0.C#D#E#F.0",
                ". # . . # .",
                "A#B.0.0.G.0",
                ". # . . # .",
                "0.H.0.0.M.0",
                ". # . . # .",
                "0.I#J#K#L.0",
            };

            TestGridFloorPlan floorPlan        = TestGridFloorPlan.InitGridToContext(inGrid);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

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

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

            var pathGen = new ConnectGridBranchStep <IGridPathTestContext> {
                ConnectPercent = 100
            };

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

            mockHalls.Setup(p => p.Pick(testRand.Object)).Returns(new TestGridRoomGen());
            pathGen.GenericHalls = mockHalls.Object;

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
        public void GetAdjacentRoomsMultiCellRepeat()
        {
            // many cell room with double dip on a room
            string[] inGrid =
            {
                "0.C.0",
                ". # .",
                "B#A#D",
                ". . .",
                "B#A#D",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            List <int>        rooms     = floorPlan.GetAdjacentRooms(0);
            List <int>        compare   = new List <int> {
                2, 1, 3
            };

            Assert.That(rooms, Is.EqualTo(compare));
        }
        public void GetAdjacentRoomsOneCellAllNear()
        {
            // completely filled one-cell room
            string[] inGrid =
            {
                "0.D.0",
                ". # .",
                "C#A#E",
                ". # .",
                "0.B.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            List <int>        rooms     = floorPlan.GetAdjacentRooms(0);
            List <int>        compare   = new List <int> {
                3, 1, 2, 4
            };

            Assert.That(rooms, Is.EqualTo(compare));
        }
Exemple #21
0
        public void CreateErrorPath()
        {
            string[] inGrid =
            {
                "0.0",
                ". .",
                "0.0",
            };

            string[] outGrid =
            {
                "A.0",
                ". .",
                "0.0",
            };

            var pathGen = new Mock <GridPathStartStepGeneric <IGridPathTestContext> > {
                CallBase = true
            };

            Moq.Language.ISetupSequentialResult <RoomGen <IGridPathTestContext> > defaultSeq = pathGen.SetupSequence(p => p.GetDefaultGen());
            defaultSeq = defaultSeq.Returns(new TestGridRoomGen('A'));

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

            pathGen.Object.GenericHalls = mockHalls.Object;
            Mock <IRandPicker <RoomGen <IGridPathTestContext> > > mockRooms = new Mock <IRandPicker <RoomGen <IGridPathTestContext> > >(MockBehavior.Strict);

            pathGen.Object.GenericRooms = mockRooms.Object;

            Mock <IRandom>    mockRand         = new Mock <IRandom>(MockBehavior.Strict);
            TestGridFloorPlan floorPlan        = TestGridFloorPlan.InitGridToContext(inGrid);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            pathGen.Object.CreateErrorPath(mockRand.Object, floorPlan);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);

            pathGen.Verify(p => p.GetDefaultGen(), Times.Exactly(1));
        }
Exemple #22
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>());
            }
        }
        public void GetAdjacentRoomsMultiCellAll()
        {
            // completely filled many-cell room
            string[] inGrid =
            {
                "0.G.H.I.0",
                ". # # # .",
                "E#A.A.A#J",
                ". . . . .",
                "F#A.A.A#K",
                ". # # # .",
                "0.B.C.D.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            List <int>        rooms     = floorPlan.GetAdjacentRooms(0);
            List <int>        compare   = new List <int> {
                6, 1, 7, 2, 8, 3, 4, 9, 5, 10
            };

            Assert.That(rooms, Is.EqualTo(compare));
        }
Exemple #24
0
        public void CreatePathMinSize()
        {
            string[] inGrid =
            {
                "0.0",
            };

            string[] outGrid =
            {
                "A#B",
            };

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

            var pathGen = new GridPathTwoSides <IGridPathTestContext> {
                GapAxis = Axis4.Horiz
            };

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

            mockHalls.Setup(p => p.Pick(testRand.Object)).Returns(new TestGridRoomGen());
            pathGen.GenericHalls = mockHalls.Object;
            Mock <IRandPicker <RoomGen <IGridPathTestContext> > > mockRooms = new Mock <IRandPicker <RoomGen <IGridPathTestContext> > >(MockBehavior.Strict);

            Moq.Language.ISetupSequentialResult <RoomGen <IGridPathTestContext> > roomSeq = mockRooms.SetupSequence(p => p.Pick(testRand.Object));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('A'));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('B'));
            pathGen.GenericRooms = mockRooms.Object;

            TestGridFloorPlan floorPlan        = TestGridFloorPlan.InitGridToContext(inGrid);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);

            mockHalls.Verify(p => p.Pick(testRand.Object), Times.Exactly(1));
            mockRooms.Verify(p => p.Pick(testRand.Object), Times.Exactly(2));
        }
        public void CreatePathSpecific()
        {
            // specific halls and rooms
            string[] inGrid =
            {
                "0.0.0",
                ". . .",
                "0.0.0",
                ". . .",
                "0.0.0",
            };

            string[] outGrid =
            {
                "A#B#C",
                ". . #",
                "H#I.D",
                "# . #",
                "G#F#E",
            };

            TestGridFloorPlan floorPlan        = TestGridFloorPlan.InitGridToContext(inGrid);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

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

            var pathGen = new GridPathSpecific <IGridPathTestContext>
            {
                SpecificVHalls = new PermissiveRoomGen <IGridPathTestContext> [3][],
            };

            for (int ii = 0; ii < 3; ii++)
            {
                pathGen.SpecificVHalls[ii] = new PermissiveRoomGen <IGridPathTestContext> [2];
            }
            pathGen.SpecificHHalls = new PermissiveRoomGen <IGridPathTestContext> [2][];
            for (int ii = 0; ii < 2; ii++)
            {
                pathGen.SpecificHHalls[ii] = new PermissiveRoomGen <IGridPathTestContext> [3];
            }

            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(0, 0, 1, 1), new TestGridRoomGen('A')));
            pathGen.SpecificHHalls[0][0] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(1, 0, 1, 1), new TestGridRoomGen('B')));
            pathGen.SpecificHHalls[1][0] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(2, 0, 1, 1), new TestGridRoomGen('C')));
            pathGen.SpecificVHalls[2][0] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(2, 1, 1, 1), new TestGridRoomGen('D')));
            pathGen.SpecificVHalls[2][1] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(2, 2, 1, 1), new TestGridRoomGen('E')));
            pathGen.SpecificHHalls[1][2] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(1, 2, 1, 1), new TestGridRoomGen('F')));
            pathGen.SpecificHHalls[0][2] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(0, 2, 1, 1), new TestGridRoomGen('G')));
            pathGen.SpecificVHalls[0][1] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(0, 1, 1, 1), new TestGridRoomGen('H')));
            pathGen.SpecificHHalls[0][1] = new TestGridRoomGen();
            pathGen.SpecificRooms.Add(new SpecificGridRoomPlan <IGridPathTestContext>(new Rect(1, 1, 1, 1), new TestGridRoomGen('I')));

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Exemple #26
0
        public void CreatePathMedSize()
        {
            string[] inGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
            };

            string[] outGrid =
            {
                "A#C.C#B",
                "# . . .",
                "D#F.F#E",
                "# . . .",
                "G#I.I#H",
            };

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

            testRand.Setup(p => p.Next(2)).Returns(0);

            var pathGen = new Mock <GridPathTwoSides <IGridPathTestContext> > {
                CallBase = true
            };

            pathGen.Object.GapAxis = Axis4.Horiz;

            Moq.Language.ISetupSequentialResult <RoomGen <IGridPathTestContext> > defaultSeq = pathGen.SetupSequence(p => p.GetDefaultGen());
            defaultSeq = defaultSeq.Returns(new TestGridRoomGen('C'));
            defaultSeq = defaultSeq.Returns(new TestGridRoomGen('F'));
            defaultSeq = defaultSeq.Returns(new TestGridRoomGen('I'));

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

            mockHalls.Setup(p => p.Pick(testRand.Object)).Returns(new TestGridRoomGen());
            pathGen.Object.GenericHalls = mockHalls.Object;
            Mock <IRandPicker <RoomGen <IGridPathTestContext> > > mockRooms = new Mock <IRandPicker <RoomGen <IGridPathTestContext> > >(MockBehavior.Strict);

            Moq.Language.ISetupSequentialResult <RoomGen <IGridPathTestContext> > roomSeq = mockRooms.SetupSequence(p => p.Pick(testRand.Object));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('A'));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('B'));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('D'));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('E'));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('G'));
            roomSeq = roomSeq.Returns(new TestGridRoomGen('H'));
            pathGen.Object.GenericRooms = mockRooms.Object;

            TestGridFloorPlan floorPlan        = TestGridFloorPlan.InitGridToContext(inGrid);
            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            pathGen.Object.ApplyToPath(testRand.Object, floorPlan);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);

            testRand.Verify(p => p.Next(2), Times.Exactly(2));
            mockHalls.Verify(p => p.Pick(testRand.Object), Times.Exactly(8));
            mockRooms.Verify(p => p.Pick(testRand.Object), Times.Exactly(6));
            pathGen.Verify(p => p.GetDefaultGen(), Times.Exactly(3));
        }
        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));
            }
        }
        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);
        }
        public void SetHallInDirs(Dir4 dir, int expectedOut)
        {
            // valid/invalid dir
            string[] inGrid =
            {
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
                ". . . .",
                "0.0.0.0",
            };

            string[] outGrid   = null;
            bool     exception = false;

            switch (expectedOut)
            {
            case 0:
                outGrid = new string[]
                {
                    "0.0.0.0",
                    ". . . .",
                    "0.0.0.0",
                    ". # . .",
                    "0.0.0.0",
                };
                break;

            case 1:
                outGrid = new string[]
                {
                    "0.0.0.0",
                    ". . . .",
                    "0#0.0.0",
                    ". . . .",
                    "0.0.0.0",
                };
                break;

            case 2:
                outGrid = new string[]
                {
                    "0.0.0.0",
                    ". # . .",
                    "0.0.0.0",
                    ". . . .",
                    "0.0.0.0",
                };
                break;

            case 3:
                outGrid = new string[]
                {
                    "0.0.0.0",
                    ". . . .",
                    "0.0#0.0",
                    ". . . .",
                    "0.0.0.0",
                };
                break;

            default:
                exception = true;
                break;
            }

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            var gen = new TestGridRoomGen((char)0);

            if (exception)
            {
                if (dir == Dir4.None)
                {
                    Assert.Throws <ArgumentException>(() => { floorPlan.SetHall(new LocRay4(1, 1, dir), gen); });
                }
                else
                {
                    Assert.Throws <ArgumentOutOfRangeException>(() => { floorPlan.SetHall(new LocRay4(1, 1, dir), gen); });
                }
                return;
            }
            else
            {
                floorPlan.SetHall(new LocRay4(1, 1, dir), gen);
            }

            TestGridFloorPlan compareFloorPlan = TestGridFloorPlan.InitGridToContext(outGrid);

            TestGridFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);

            // set existing hall to null
        }