Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
0
        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
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
        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);
        }