Example #1
0
        public void GetConfigurationSpaceOverCorridor_SquareRoomSquareCorridor()
        {
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();

            var basicRoomTemplate         = new RoomTemplate(PolygonGrid2D.GetSquare(5), new SimpleDoorMode(1, 0), transformations);
            var basicRoomTemplateInstance = generator.GetRoomTemplateInstances(basicRoomTemplate).First();

            var corridorRoomTemplate = new RoomTemplate(PolygonGrid2D.GetSquare(2), new ManualDoorMode(new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(1, 0)),
                new OrthogonalLineGrid2D(new Vector2Int(1, 0), new Vector2Int(2, 0)),
                new OrthogonalLineGrid2D(new Vector2Int(0, 2), new Vector2Int(1, 2)),
                new OrthogonalLineGrid2D(new Vector2Int(1, 2), new Vector2Int(2, 2)),
            }), transformations);
            var corridorRoomTemplateInstances = generator.GetRoomTemplateInstances(corridorRoomTemplate);

            var expectedLines = new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(-7, -5), new Vector2Int(-7, 5)),
                new OrthogonalLineGrid2D(new Vector2Int(7, -5), new Vector2Int(7, 5)),
                new OrthogonalLineGrid2D(new Vector2Int(-5, 7), new Vector2Int(5, 7)),
                new OrthogonalLineGrid2D(new Vector2Int(-5, -7), new Vector2Int(5, -7)),
            };

            var expectedPoints = expectedLines
                                 .SelectMany(x => x.GetPoints())
                                 .Distinct()
                                 .ToList();

            var configurationSpace = generator.GetConfigurationSpaceOverCorridors(basicRoomTemplateInstance,
                                                                                  basicRoomTemplateInstance, corridorRoomTemplateInstances);

            Assert.That(configurationSpace.Lines.SelectMany(x => x.GetPoints()), Is.EquivalentTo(expectedPoints));
        }
        public void DifferentTransformationsProperlyHandled()
        {
            var roomTemplate1   = GetRoomTemplate(RoomTemplateRepeatMode.NoRepeat, TransformationGrid2DHelper.GetAllTransformationsOld().ToList());
            var roomDescription = new BasicRoomDescription(new List <RoomTemplate>()
            {
                roomTemplate1
            });

            var mapDescription      = GetMapDescription(roomDescription);
            var configurationSpaces = GetConfigurationSpaces(mapDescription);

            var roomShapesHandler = new RoomShapesHandler <int, Configuration <CorridorsData> >(
                configurationSpaces,
                configurationSpaces.GetIntAliasMapping(),
                mapDescription
                );

            var roomShapes = configurationSpaces.GetIntAliasMapping().Values.ToList();
            var layout     = new Layout <Configuration <CorridorsData> >(mapDescription.GetGraph());

            SetConfiguration(layout, 0, roomShapes[0]);

            {
                var shapes = roomShapesHandler.GetPossibleShapesForNode(layout, 1);
                Assert.That(shapes.Count, Is.Zero);
            }
        }
Example #3
0
        public static List <RoomTemplate> GetCorridorRoomTemplates(List <int> offsets, int width = 1)
        {
            if (offsets == null)
            {
                return(null);
            }

            var roomTemplates   = new List <RoomTemplate>();
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();

            foreach (var offset in offsets)
            {
                var length       = offset;
                var roomTemplate = new RoomTemplate(
                    PolygonGrid2D.GetRectangle(length, width),
                    new ManualDoorMode(new List <OrthogonalLineGrid2D>()
                {
                    new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, width)),
                    new OrthogonalLineGrid2D(new Vector2Int(length, 0), new Vector2Int(length, width)),
                }),
                    transformations
                    );

                roomTemplates.Add(roomTemplate);
            }

            return(roomTemplates);
        }
Example #4
0
        public static List <RoomTemplateGrid2D> GetNewCorridorRoomTemplates(List <int> offsets, int width = 1)
        {
            if (offsets == null)
            {
                return(null);
            }

            var roomTemplates   = new List <RoomTemplateGrid2D>();
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();

            foreach (var offset in offsets)
            {
                var length       = offset;
                var roomTemplate = new RoomTemplateGrid2D(
                    PolygonGrid2D.GetRectangle(length, width),
                    new ManualDoorModeGrid2D(new List <DoorGrid2D>()
                {
                    new DoorGrid2D(new Vector2Int(0, 0), new Vector2Int(0, width)),
                    new DoorGrid2D(new Vector2Int(length, 0), new Vector2Int(length, width)),
                }),
                    allowedTransformations: transformations,
                    repeatMode: RoomTemplateRepeatMode.AllowRepeat
                    );

                roomTemplates.Add(roomTemplate);
            }

            return(roomTemplates);
        }
        public void ComputeAverageRoomTemplatesEntropy_BasicTest()
        {
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();
            var roomTemplate1   = new RoomTemplate(PolygonGrid2D.GetSquare(10), new SimpleDoorMode(1, 0), transformations);
            var roomTemplate2   = new RoomTemplate(PolygonGrid2D.GetRectangle(5, 10), new SimpleDoorMode(1, 0), transformations);

            var roomDescription1 = new BasicRoomDescription(new List <RoomTemplate>()
            {
                roomTemplate1, roomTemplate2
            });

            var mapDescription = new MapDescription <int>();

            mapDescription.AddRoom(0, roomDescription1);
            mapDescription.AddRoom(1, roomDescription1);
            mapDescription.AddConnection(0, 1);

            var dungeonGenerator = new DungeonGenerator <int>(mapDescription);

            dungeonGenerator.InjectRandomGenerator(new Random(0));

            var layouts = new List <MapLayout <int> >();

            for (int i = 0; i < 10; i++)
            {
                layouts.Add(dungeonGenerator.GenerateLayout());
            }

            var entropy = entropyCalculator.ComputeAverageRoomTemplatesEntropy(mapDescription, layouts);

            Assert.That(entropy, Is.GreaterThanOrEqualTo(0));
            Assert.That(entropy, Is.LessThanOrEqualTo(1));
        }
        public void GetRoomTemplatesDistribution_BasicTest()
        {
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();
            var roomTemplate1   = new RoomTemplate(PolygonGrid2D.GetSquare(2), new SimpleDoorMode(1, 0), transformations);
            var roomTemplate2   = new RoomTemplate(PolygonGrid2D.GetSquare(4), new SimpleDoorMode(1, 0), transformations);
            var roomTemplate3   = new RoomTemplate(PolygonGrid2D.GetSquare(6), new SimpleDoorMode(1, 0), transformations);

            var data = new List <RoomTemplate>()
            {
                roomTemplate1,
                roomTemplate3,
                roomTemplate1,
                roomTemplate1
            };

            var availableRoomTemplates = new List <RoomTemplate>()
            {
                roomTemplate1,
                roomTemplate2,
                roomTemplate3,
            };

            var distribution = entropyCalculator.GetProbabilityDistribution(data, availableRoomTemplates);

            Assert.That(distribution.Count, Is.EqualTo(3));
            Assert.That(distribution[roomTemplate1], Is.EqualTo(3 / 4d));
            Assert.That(distribution[roomTemplate2], Is.EqualTo(0));
            Assert.That(distribution[roomTemplate3], Is.EqualTo(1 / 4d));
        }
Example #7
0
        public static List <RoomTemplate> GetRectangularRoomTemplates(Vector2Int scale)
        {
            var overlapScale    = Math.Min(scale.X, scale.Y);
            var doorMode        = new SimpleDoorMode(1 * overlapScale, 0);
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();

            var squareRoom    = new RoomTemplate(PolygonGrid2D.GetSquare(6).Scale(scale), doorMode, transformations, name: "Square");
            var rectangleRoom = new RoomTemplate(PolygonGrid2D.GetRectangle(6, 9).Scale(scale), doorMode, transformations, name: "Rectangle");

            return(new List <RoomTemplate>()
            {
                squareRoom,
                rectangleRoom,
            });
        }
Example #8
0
        public static List <RoomTemplate> GetBasicRoomTemplates(Vector2Int scale)
        {
            var overlapScale    = Math.Min(scale.X, scale.Y);
            var doorMode        = new SimpleDoorMode(1 * overlapScale, 0);
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();

            var room1 = new RoomTemplate(
                new PolygonGrid2DBuilder()
                .AddPoint(0, 0)
                .AddPoint(0, 6)
                .AddPoint(3, 6)
                .AddPoint(3, 3)
                .AddPoint(6, 3)
                .AddPoint(6, 0)
                .Build().Scale(scale)
                , doorMode, transformations, name: "L-shape");
            var room2 = new RoomTemplate(
                new PolygonGrid2DBuilder()
                .AddPoint(0, 0)
                .AddPoint(0, 9)
                .AddPoint(3, 9)
                .AddPoint(3, 3)
                .AddPoint(6, 3)
                .AddPoint(6, 0)
                .Build().Scale(scale)
                , doorMode, transformations, name: "L-shape long");
            var room3 = new RoomTemplate(
                new PolygonGrid2DBuilder()
                .AddPoint(0, 0)
                .AddPoint(0, 3)
                .AddPoint(3, 3)
                .AddPoint(3, 6)
                .AddPoint(6, 6)
                .AddPoint(6, 3)
                .AddPoint(9, 3)
                .AddPoint(9, 0)
                .Build().Scale(scale)
                , doorMode, transformations, name: "T-shape");

            return(new List <RoomTemplate>(GetRectangularRoomTemplates(scale))
            {
                room1,
                room2,
                room3,
            });
        }
Example #9
0
        public void GetRoomTemplateInstances_SquareAllTransformationsOneDoor_ReturnsFourInstance()
        {
            var roomShape = PolygonGrid2D.GetSquare(10);
            var doorsMode = new ManualDoorMode(new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(1, 0))
            });
            var transformations = TransformationGrid2DHelper.GetAllTransformationsOld().ToList();

            var expectedDoorPositions = new Dictionary <TransformationGrid2D, DoorLine>()
            {
                { TransformationGrid2D.Identity, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(1, 0), new Vector2Int(1, 0)), 1) },
                { TransformationGrid2D.Rotate90, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 9), new Vector2Int(0, 9)), 1) },
                { TransformationGrid2D.Rotate180, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(9, 10), new Vector2Int(9, 10)), 1) },
                { TransformationGrid2D.Rotate270, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(10, 1), new Vector2Int(10, 1)), 1) },

                { TransformationGrid2D.MirrorY, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(10, 0), new Vector2Int(10, 0)), 1) },
                { TransformationGrid2D.MirrorX, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 10), new Vector2Int(0, 10)), 1) },
                { TransformationGrid2D.Diagonal13, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 0)), 1) },
                { TransformationGrid2D.Diagonal24, new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(10, 10), new Vector2Int(10, 10)), 1) },
            };

            var roomTemplate = new RoomTemplate(roomShape, doorsMode, transformations);
            var instances    = generator.GetRoomTemplateInstances(roomTemplate);

            Assert.That(instances.Count, Is.EqualTo(8));

            foreach (var instance in instances)
            {
                Assert.That(instance.RoomShape, Is.EqualTo(roomShape));
                Assert.That(instance.Transformations.Count, Is.EqualTo(1));

                var transformation = instance.Transformations[0];

                Assert.That(instance.DoorLines.Count, Is.EqualTo(1));
                Assert.That(instance.DoorLines[0].Length, Is.EqualTo(expectedDoorPositions[transformation].Length));
                Assert.That(instance.DoorLines[0].Line, Is.EqualTo(expectedDoorPositions[transformation].Line));
            }
        }
 /// <summary>
 /// Gets all available room templates for corridor rooms.
 /// </summary>
 private List <RoomTemplateGrid2D> GetCorridorRoomTemplates()
 {
     return(new List <RoomTemplateGrid2D>()
     {
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetRectangle(4, 3),
             new ManualDoorModeGrid2D(new List <DoorGrid2D>()
         {
             new DoorGrid2D(new Vector2Int(0, 1), new Vector2Int(0, 2)),
             new DoorGrid2D(new Vector2Int(4, 1), new Vector2Int(4, 2)),
         }
                                      ),
             allowedTransformations: TransformationGrid2DHelper.GetRotations()
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetRectangle(6, 3),
             new ManualDoorModeGrid2D(new List <DoorGrid2D>()
         {
             new DoorGrid2D(new Vector2Int(0, 1), new Vector2Int(0, 2)),
             new DoorGrid2D(new Vector2Int(6, 1), new Vector2Int(6, 2)),
         }
                                      ),
             allowedTransformations: TransformationGrid2DHelper.GetRotations()
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetRectangle(8, 3),
             new ManualDoorModeGrid2D(new List <DoorGrid2D>()
         {
             new DoorGrid2D(new Vector2Int(0, 1), new Vector2Int(0, 2)),
             new DoorGrid2D(new Vector2Int(8, 1), new Vector2Int(8, 2)),
         }
                                      ),
             allowedTransformations: TransformationGrid2DHelper.GetRotations()
             ),
     });
 }
        /// <summary>
        /// Gets a room description that cannot be draw because every room template has only a single door position
        /// but there is a room that should be connected to two other rooms.
        /// </summary>
        /// <returns></returns>
        public static MapDescription <int> GetImpossibleMapDescription()
        {
            var roomShape     = PolygonGrid2D.GetSquare(3);
            var doorPositions = new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 1)),
            };

            var roomTemplate    = new RoomTemplate(roomShape, new ManualDoorMode(doorPositions), TransformationGrid2DHelper.GetAllTransformationsOld().ToList());
            var roomDescription = new BasicRoomDescription(new List <RoomTemplate>()
            {
                roomTemplate
            });

            var mapDescription = new MapDescription <int>();

            mapDescription.AddRoom(0, roomDescription);
            mapDescription.AddRoom(1, roomDescription);
            mapDescription.AddRoom(2, roomDescription);
            mapDescription.AddConnection(0, 1);
            mapDescription.AddConnection(0, 2);

            return(mapDescription);
        }
        public void SimpleMapDescriptionTest()
        {
            var roomTemplate1 = new RoomTemplate(PolygonGrid2D.GetSquare(10), new SimpleDoorMode(1, 0), TransformationGrid2DHelper.GetAllTransformationsOld().ToList());
            var roomTemplate2 = new RoomTemplate(PolygonGrid2D.GetRectangle(5, 10), new SimpleDoorMode(1, 0), TransformationGrid2DHelper.GetAllTransformationsOld().ToList());

            var roomDescription1 = new BasicRoomDescription(new List <RoomTemplate>()
            {
                roomTemplate1
            });
            var roomDescription2 = new BasicRoomDescription(new List <RoomTemplate>()
            {
                roomTemplate2
            });

            var mapDescription = new MapDescription <int>();

            mapDescription.AddRoom(0, roomDescription1);
            mapDescription.AddRoom(1, roomDescription2);
            mapDescription.AddConnection(0, 1);

            var dungeonGenerator = new DungeonGenerator <int>(mapDescription);

            dungeonGenerator.InjectRandomGenerator(new Random(0));

            var layout = dungeonGenerator.GenerateLayout();

            Assert.That(layout, Is.Not.Null);
            Assert.That(layout.Rooms.Count(), Is.EqualTo(2));
        }
 /// <summary>
 /// Gets all available room templates for non-corridor rooms.
 /// </summary>
 /// <returns></returns>
 private Dictionary <string, RoomTemplateGrid2D> GetRoomTemplates()
 {
     return(new List <RoomTemplateGrid2D>()
     {
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetRectangle(15, 19),
             new SimpleDoorModeGrid2D(1, 2),
             allowedTransformations: TransformationGrid2DHelper.GetRotations(),
             name: "Normal 1"
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetRectangle(13, 15),
             new SimpleDoorModeGrid2D(1, 2),
             allowedTransformations: TransformationGrid2DHelper.GetRotations(),
             name: "Normal 2"
             ),
         new RoomTemplateGrid2D(
             new PolygonGrid2DBuilder()
             .AddPoint(-11, 6).AddPoint(-5, 6).AddPoint(-5, 5).AddPoint(-3, 5)
             .AddPoint(-3, 6).AddPoint(2, 6).AddPoint(2, 5).AddPoint(4, 5)
             .AddPoint(4, 6).AddPoint(10, 6).AddPoint(10, -1).AddPoint(4, -1)
             .AddPoint(4, 0).AddPoint(2, 0).AddPoint(2, -1).AddPoint(-3, -1)
             .AddPoint(-3, 0).AddPoint(-5, 0).AddPoint(-5, -1).AddPoint(-11, -1)
             .Build(),
             new SimpleDoorModeGrid2D(1, 2),
             // repeatMode: RoomTemplateRepeatMode.NoRepeat,
             allowedTransformations: TransformationGrid2DHelper.GetRotations(),
             name: "Normal 3"
             ),
         #region hidden:Other room templates
         new RoomTemplateGrid2D(
             new PolygonGrid2DBuilder()
             .AddPoint(-39, 1).AddPoint(-37, 1).AddPoint(-37, 10).AddPoint(-39, 10)
             .AddPoint(-39, 15).AddPoint(-26, 15).AddPoint(-26, 10).AddPoint(-28, 10)
             .AddPoint(-28, 1).AddPoint(-26, 1).AddPoint(-26, -4).AddPoint(-39, -4)
             .Build(),
             new SimpleDoorModeGrid2D(1, 2),
             allowedTransformations: TransformationGrid2DHelper.GetRotations(),
             name: "Normal 4"
             ),
         new RoomTemplateGrid2D(
             new PolygonGrid2DBuilder()
             .AddPoint(-14, 3).AddPoint(0, 3).AddPoint(0, 5).AddPoint(-14, 5)
             .AddPoint(-14, 12).AddPoint(8, 12).AddPoint(8, -4).AddPoint(-6, -4)
             .AddPoint(-6, -6).AddPoint(8, -6).AddPoint(8, -13).AddPoint(-14, -13)
             .Build(),
             new SimpleDoorModeGrid2D(1, 2),
             // repeatMode: RoomTemplateRepeatMode.NoRepeat,
             name: "Normal 5"
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetSquare(13),
             new SimpleDoorModeGrid2D(1, 2),
             name: "Normal 6"
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetSquare(11),
             new SimpleDoorModeGrid2D(1, 2),
             name: "Spawn"
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetRectangle(26, 26),
             new SimpleDoorModeGrid2D(1, 4),
             allowedTransformations: TransformationGrid2DHelper.GetRotations(),
             name: "Boss"
             ),
         new RoomTemplateGrid2D(PolygonGrid2D.GetRectangle(20, 26),
                                new SimpleDoorModeGrid2D(1, 4),
                                allowedTransformations: TransformationGrid2DHelper.GetRotations(),
                                name: "Hub 1"
                                ),
         new RoomTemplateGrid2D(
             new PolygonGrid2DBuilder()
             .AddPoint(-8, 7).AddPoint(-7, 7).AddPoint(-7, 8).AddPoint(3, 8)
             .AddPoint(3, 7).AddPoint(4, 7).AddPoint(4, -3).AddPoint(3, -3)
             .AddPoint(3, -4).AddPoint(-7, -4).AddPoint(-7, -3).AddPoint(-8, -3)
             .Build(),
             new SimpleDoorModeGrid2D(1, 2),
             name: "Reward"
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetRectangle(12, 17),
             new SimpleDoorModeGrid2D(1, 3),
             allowedTransformations: TransformationGrid2DHelper.GetRotations(),
             name: "Normal 7"
             ),
         new RoomTemplateGrid2D(
             new PolygonGrid2DBuilder()
             .AddPoint(-3, 4).AddPoint(4, 4).AddPoint(4, -1).AddPoint(-3, -1)
             .Build(),
             new ManualDoorModeGrid2D(new List <DoorGrid2D>()
         {
             new DoorGrid2D(new Vector2Int(4, 2), new Vector2Int(4, 1)),
             new DoorGrid2D(new Vector2Int(-3, 2), new Vector2Int(-3, 1)),
             new DoorGrid2D(new Vector2Int(0, 4), new Vector2Int(1, 4)),
             new DoorGrid2D(new Vector2Int(0, -1), new Vector2Int(1, -1)),
         }
                                      ),
             name: "Exit"
             ),
         new RoomTemplateGrid2D(
             new PolygonGrid2DBuilder()
             .AddPoint(-8, 7).AddPoint(-7, 7).AddPoint(-7, 8).AddPoint(3, 8)
             .AddPoint(3, 7).AddPoint(4, 7).AddPoint(4, -3).AddPoint(3, -3)
             .AddPoint(3, -4).AddPoint(-7, -4).AddPoint(-7, -3).AddPoint(-8, -3)
             .Build(),
             new SimpleDoorModeGrid2D(1, 2),
             name: "Shop"
             ),
         new RoomTemplateGrid2D(
             PolygonGrid2D.GetSquare(9),
             new SimpleDoorModeGrid2D(1, 2),
             name: "Secret"
             )
         #endregion
     }.ToDictionary(x => x.Name, x => x));
 }
Example #14
0
        public MapDescription <int> GetMapDescription()
        {
            const bool useLongCorridors    = false;
            const bool useLShapedCorridors = false;
            const bool useWideCorridors    = false;

            // Create basic room templates and room description
            var doorMode = new SimpleDoorMode(1, 1);

            var squareRoom = new RoomTemplate(
                PolygonGrid2D.GetSquare(8),
                doorMode
                );

            var rectangleRoom = new RoomTemplate(
                PolygonGrid2D.GetRectangle(6, 10),
                doorMode,
                new List <TransformationGrid2D>()
            {
                TransformationGrid2D.Identity, TransformationGrid2D.Rotate90
            }
                );

            var basicRoomDescription = new BasicRoomDescription(new List <RoomTemplate>()
            {
                squareRoom, rectangleRoom
            });

            // Basic corridor shape
            var corridorRoom1x2 = new RoomTemplate(
                PolygonGrid2D.GetRectangle(1, 2),
                new ManualDoorMode(new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(1, 0)),
                new OrthogonalLineGrid2D(new Vector2Int(0, 2), new Vector2Int(1, 2))
            }),
                new List <TransformationGrid2D>()
            {
                TransformationGrid2D.Identity, TransformationGrid2D.Rotate90
            }
                );

            var corridorRoomDescription = new CorridorRoomDescription(new List <RoomTemplate>()
            {
                corridorRoom1x2
            });

            // Add longer corridor
            if (useLongCorridors)
            {
                var corridorRoom1x4 = new RoomTemplate(
                    PolygonGrid2D.GetRectangle(1, 4),
                    new ManualDoorMode(new List <OrthogonalLineGrid2D>()
                {
                    new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(1, 0)),
                    new OrthogonalLineGrid2D(new Vector2Int(0, 4), new Vector2Int(1, 4))
                }),
                    new List <TransformationGrid2D>()
                {
                    TransformationGrid2D.Identity, TransformationGrid2D.Rotate90
                }
                    );

                corridorRoomDescription.RoomTemplates.Add(corridorRoom1x4);
            }

            // Add l-shaped corridor
            if (useLShapedCorridors)
            {
                var corridorRoomLShaped = new RoomTemplate(
                    new PolygonGrid2DBuilder()
                    .AddPoint(0, 2)
                    .AddPoint(0, 3)
                    .AddPoint(3, 3)
                    .AddPoint(3, 0)
                    .AddPoint(2, 0)
                    .AddPoint(2, 2)
                    .Build(),
                    new ManualDoorMode(new List <OrthogonalLineGrid2D>()
                {
                    new OrthogonalLineGrid2D(new Vector2Int(0, 2), new Vector2Int(0, 3)),
                    new OrthogonalLineGrid2D(new Vector2Int(2, 0), new Vector2Int(3, 0))
                }),
                    TransformationGrid2DHelper.GetAllTransformationsOld().ToList()
                    );

                corridorRoomDescription.RoomTemplates.Add(corridorRoomLShaped);
            }

            // Add wide corridor
            if (useWideCorridors)
            {
                var corridorWide = new RoomTemplate(
                    new PolygonGrid2DBuilder()
                    .AddPoint(1, 0)
                    .AddPoint(1, 1)
                    .AddPoint(0, 1)
                    .AddPoint(0, 4)
                    .AddPoint(1, 4)
                    .AddPoint(1, 5)
                    .AddPoint(2, 5)
                    .AddPoint(2, 4)
                    .AddPoint(3, 4)
                    .AddPoint(3, 1)
                    .AddPoint(2, 1)
                    .AddPoint(2, 0)
                    .Build(),
                    new ManualDoorMode(new List <OrthogonalLineGrid2D>()
                {
                    new OrthogonalLineGrid2D(new Vector2Int(1, 0), new Vector2Int(2, 0)),
                    new OrthogonalLineGrid2D(new Vector2Int(1, 5), new Vector2Int(2, 5))
                }),
                    TransformationGrid2DHelper.GetAllTransformationsOld().ToList()
                    );

                corridorRoomDescription.RoomTemplates.Add(corridorWide);
            }

            // Create map description
            var mapDescription = new MapDescription <int>();
            var graph          = GraphsDatabase.GetExample1();

            // Add non-corridor rooms
            foreach (var room in graph.Vertices)
            {
                mapDescription.AddRoom(room, basicRoomDescription);
            }

            // We need to somehow identify our corridor rooms
            // Here we simply number them and keep track which was the last used number
            var counter = graph.VerticesCount;

            foreach (var connection in graph.Edges)
            {
                if (true)
                {
                    if (true)
                    {
                        if (connection.From % 2 == 0 && connection.To % 2 == 0)
                        {
                            // We manually insert a new node between each neighboring nodes in the graph
                            mapDescription.AddRoom(counter, corridorRoomDescription);

                            // And instead of connecting the rooms directly, we connect them to the corridor room
                            mapDescription.AddConnection(connection.From, counter);
                            mapDescription.AddConnection(connection.To, counter);
                            counter++;
                        }
                        else
                        {
                            mapDescription.AddConnection(connection.From, connection.To);
                        }
                    }
                    else
                    {
                        var desc1 = new CorridorRoomDescription(new List <RoomTemplate>()
                        {
                            corridorRoomDescription.RoomTemplates[0]
                        });
                        var desc2 = new CorridorRoomDescription(new List <RoomTemplate>()
                        {
                            corridorRoomDescription.RoomTemplates[1]
                        });

                        // We manually insert a new node between each neighboring nodes in the graph
                        mapDescription.AddRoom(counter, connection.From % 2 == 0 && connection.To % 2 == 0 ? desc2 : desc1);

                        // And instead of connecting the rooms directly, we connect them to the corridor room
                        mapDescription.AddConnection(connection.From, counter);
                        mapDescription.AddConnection(connection.To, counter);
                        counter++;
                    }
                }
                else
                {
                    // We manually insert a new node between each neighboring nodes in the graph
                    mapDescription.AddRoom(counter, corridorRoomDescription);

                    // And instead of connecting the rooms directly, we connect them to the corridor room
                    mapDescription.AddConnection(connection.From, counter);
                    mapDescription.AddConnection(connection.To, counter);
                    counter++;
                }
            }

            return(mapDescription);
        }
Example #15
0
        public void Generate_BasicTest()
        {
            var roomTemplate1 = new RoomTemplate(PolygonGrid2D.GetSquare(10), new SimpleDoorMode(1, 0), TransformationGrid2DHelper.GetAllTransformationsOld().ToList());
            var roomTemplate2 = new RoomTemplate(PolygonGrid2D.GetRectangle(5, 10), new SimpleDoorMode(1, 0), TransformationGrid2DHelper.GetAllTransformationsOld().ToList());

            var roomDescription1 = new BasicRoomDescription(new List <RoomTemplate>()
            {
                roomTemplate1
            });
            var roomDescription2 = new BasicRoomDescription(new List <RoomTemplate>()
            {
                roomTemplate1, roomTemplate2
            });

            var mapDescription = new MapDescription <int>();

            mapDescription.AddRoom(0, roomDescription1);
            mapDescription.AddRoom(1, roomDescription2);
            mapDescription.AddConnection(0, 1);

            var configurationSpaces = generator.GetConfigurationSpaces <Configuration <CorridorsData> >(mapDescription);

            Assert.That(configurationSpaces.GetShapesForNode(0).Count, Is.EqualTo(1));
            Assert.That(configurationSpaces.GetShapesForNode(1).Count, Is.EqualTo(3));
            Assert.That(configurationSpaces.GetAllShapes().Count, Is.EqualTo(3));
        }