예제 #1
0
        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));
        }
예제 #2
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);
        }
예제 #3
0
    private RoomDescriptionGrid2D GetStartEndRoomDescription()
    {
        var roomsTemplates = new List <RoomTemplateGrid2D>();
        var doors          = new SimpleDoorModeGrid2D(doorLength: 1, cornerDistance: 2);

        System.Random rnd = new System.Random();

        var transformations = new List <TransformationGrid2D>()
        {
            TransformationGrid2D.Identity
        };


        var roomTemplate = new RoomTemplateGrid2D(
            PolygonGrid2D.GetRectangle(roomMinWidth, roomMinHeight),
            doors,
            allowedTransformations: transformations);

        roomsTemplates.Add(roomTemplate);


        var roomDescription = new RoomDescriptionGrid2D
                              (
            isCorridor: false,
            roomTemplates: roomsTemplates
                              );

        return(roomDescription);
    }
예제 #4
0
        public void GetRoomTemplateInstances_RectangleAllRotations_ReturnsTwoInstances()
        {
            var roomShape = PolygonGrid2D.GetRectangle(5, 10);

            var doorsMode       = new SimpleDoorMode(1, 0);
            var transformations = new List <TransformationGrid2D>()
            {
                TransformationGrid2D.Identity, TransformationGrid2D.Rotate90, TransformationGrid2D.Rotate180, TransformationGrid2D.Rotate270
            };

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

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

            var wideRectangle = instances[0];
            var tallRectangle = instances[1];

            if (wideRectangle.RoomShape.Equals(roomShape))
            {
                wideRectangle = instances[1];
                tallRectangle = instances[0];
            }

            Assert.That(tallRectangle.RoomShape, Is.EqualTo(PolygonGrid2D.GetRectangle(5, 10)));
            Assert.That(wideRectangle.RoomShape, Is.EqualTo(PolygonGrid2D.GetRectangle(10, 5)));
        }
예제 #5
0
        public void Run()
        {
            // Create square room template
            var squareRoomTemplate = new RoomTemplateGrid2D(
                PolygonGrid2D.GetSquare(8),
                new SimpleDoorModeGrid2D(doorLength: 1, cornerDistance: 1)
                );

            // Create rectangle room template
            var rectangleRoomTemplate = new RoomTemplateGrid2D(
                PolygonGrid2D.GetRectangle(6, 10),
                new SimpleDoorModeGrid2D(doorLength: 1, cornerDistance: 1)
                );

            // Create a room description which says that the room is not a corridor and that it can use the two room templates
            var roomDescription = new RoomDescriptionGrid2D(
                isCorridor: false,
                roomTemplates: new List <RoomTemplateGrid2D>()
            {
                squareRoomTemplate, rectangleRoomTemplate
            }
                );

            // Create an instance of the level description
            var levelDescription = new LevelDescriptionGrid2D <int>();

            // Add 4 rooms to the level, use the room description that we created beforehand
            levelDescription.AddRoom(0, roomDescription);
            levelDescription.AddRoom(1, roomDescription);
            levelDescription.AddRoom(2, roomDescription);
            levelDescription.AddRoom(3, roomDescription);

            // Add connections between the rooms - the level graph will be a cycle with 4 vertices
            levelDescription.AddConnection(0, 1);
            levelDescription.AddConnection(0, 3);
            levelDescription.AddConnection(1, 2);
            levelDescription.AddConnection(2, 3);

            // Create an instance of the generate and generate a layout
            var generator = new GraphBasedGeneratorGrid2D <int>(levelDescription);
            var layout    = generator.GenerateLayout();

            // Export the resulting layout as PNG
            var drawer = new DungeonDrawer <int>();

            drawer.DrawLayoutAndSave(layout, "simple_layout.png", new DungeonDrawerOptions()
            {
                Width  = 2000,
                Height = 2000,
            });

            var layout2 = generator.GenerateLayout();

            // Export the resulting layout as PNG
            drawer.DrawLayoutAndSave(layout, "simple_layout_2.png", new DungeonDrawerOptions()
            {
                Width  = 2000,
                Height = 2000,
            });
        }
예제 #6
0
        public void OverlapArea_NonTouching_ReturnsZero()
        {
            var r1 = PolygonGrid2D.GetSquare(6);
            var r2 = PolygonGrid2D.GetRectangle(2, 8);

            Assert.AreEqual(0, polygonOverlap.OverlapArea(r1, new Vector2Int(0, 0), r2, new Vector2Int(7, 2)));
        }
예제 #7
0
        public void OverlapArea_TwoRectangles()
        {
            var r1 = PolygonGrid2D.GetRectangle(4, 6);
            var r2 = PolygonGrid2D.GetRectangle(5, 3);

            Assert.AreEqual(9, polygonOverlap.OverlapArea(r1, new Vector2Int(0, 0), r2, new Vector2Int(1, 2)));
        }
예제 #8
0
        private List <RoomTemplate> GetMediumRoomTemplates()
        {
            var roomTemplates = new List <RoomTemplate>();
            var doorMode      = new SimpleDoorMode(2, 2);

            roomTemplates.Add(new RoomTemplate(PolygonGrid2D.GetSquare(12), doorMode, transformations, name: "Square 12x12", repeatMode: repeatMode));
            roomTemplates.Add(new RoomTemplate(PolygonGrid2D.GetSquare(14), doorMode, transformations, name: "Square 14x14", repeatMode: repeatMode));
            roomTemplates.Add(new RoomTemplate(PolygonGrid2D.GetRectangle(10, 14), doorMode, transformations, name: "Rectangle 10x14", repeatMode: repeatMode));
            roomTemplates.Add(new RoomTemplate(PolygonGrid2D.GetRectangle(12, 15), doorMode, transformations, name: "Rectangle 12x15", repeatMode: repeatMode));

            //roomTemplates.Add(new RoomTemplate(
            //    new GridPolygonBuilder()
            //        .AddPoint(0, 0)
            //        .AddPoint(0, 16)
            //        .AddPoint(8, 16)
            //        .AddPoint(8, 8)
            //        .AddPoint(16, 8)
            //        .AddPoint(16, 0)
            //        .Build()
            //    , doorMode, transformations, name: "L-shape large", repeatMode: RepeatMode.NoRepeat));

            if (enhanceRoomTemplates)
            {
                roomTemplates.Add(new RoomTemplate(PolygonGrid2D.GetSquare(13), doorMode, transformations, name: "Square 13x13", repeatMode: repeatMode));
                roomTemplates.Add(new RoomTemplate(PolygonGrid2D.GetRectangle(10, 16), doorMode, transformations, name: "Rectangle 10x16", repeatMode: repeatMode));
            }

            return(roomTemplates);
        }
예제 #9
0
        public void GetConfigurationSpaceOverCorridor_SquareRoomHorizontalVerticalCorridors()
        {
            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.GetRectangle(2, 1), new ManualDoorMode(new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(0, 1), new Vector2Int(0, 0)),
                new OrthogonalLineGrid2D(new Vector2Int(2, 0), new Vector2Int(2, 1)),
            }), transformations);
            var corridorRoomTemplateInstances = generator.GetRoomTemplateInstances(corridorRoomTemplate);

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

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

            Assert.That(configurationSpace.Lines.SelectMany(x => x.GetPoints()), Is.EquivalentTo(expectedLines.SelectMany(x => x.GetPoints())));
        }
예제 #10
0
        public void Rectangle_LengthZeroCorners()
        {
            var polygon = PolygonGrid2D.GetRectangle(3, 5);
            var mode    = new ManualDoorMode(new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 0)),
                new OrthogonalLineGrid2D(new Vector2Int(0, 5), new Vector2Int(0, 5)),
                new OrthogonalLineGrid2D(new Vector2Int(3, 5), new Vector2Int(3, 5)),
                new OrthogonalLineGrid2D(new Vector2Int(3, 0), new Vector2Int(3, 0)),
            });
            var doorPositions = overlapModeHandler.GetDoorPositions(polygon, mode);

            var expectedPositions = new List <DoorLine>()
            {
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 0), OrthogonalLineGrid2D.Direction.Left), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 0), OrthogonalLineGrid2D.Direction.Top), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 5), new Vector2Int(0, 5), OrthogonalLineGrid2D.Direction.Top), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 5), new Vector2Int(0, 5), OrthogonalLineGrid2D.Direction.Right), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(3, 5), new Vector2Int(3, 5), OrthogonalLineGrid2D.Direction.Right), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(3, 5), new Vector2Int(3, 5), OrthogonalLineGrid2D.Direction.Bottom), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(3, 0), new Vector2Int(3, 0), OrthogonalLineGrid2D.Direction.Bottom), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(3, 0), new Vector2Int(3, 0), OrthogonalLineGrid2D.Direction.Left), 0),
            };

            Assert.IsTrue(doorPositions.SequenceEqualWithoutOrder(expectedPositions));
        }
예제 #11
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));
        }
예제 #12
0
        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));
        }
        public void BasicTest()
        {
            var roomTemplate1 = new RoomTemplate(PolygonGrid2D.GetSquare(10), new SimpleDoorMode(1, 0));
            var roomTemplate2 = new RoomTemplate(PolygonGrid2D.GetRectangle(5, 10), new SimpleDoorMode(1, 0));

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

            var mapDescription = new MapDescription <string>();

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

            var mapDescriptionMapping = new MapDescriptionMapping <string>(mapDescription);
            var mapping = mapDescriptionMapping.GetMapping();

            Assert.That(mapDescriptionMapping.GetRoomDescription(mapping["0"]), Is.EqualTo(roomDescription1));
            Assert.That(mapDescriptionMapping.GetRoomDescription(mapping["1"]), Is.EqualTo(roomDescription2));
            Assert.That(mapDescriptionMapping.GetGraph().VerticesCount, Is.EqualTo(2));
            Assert.That(mapDescriptionMapping.GetGraph().HasEdge(mapping["0"], mapping["1"]), Is.True);
        }
예제 #14
0
        public void BoudingRectangle_ReturnsBoundingBox()
        {
            {
                var p = PolygonGrid2D.GetRectangle(2, 4);

                var boundingRectangle = p.BoundingRectangle;
                var expected          = new RectangleGrid2D(new Vector2Int(0, 0), new Vector2Int(2, 4));

                Assert.AreEqual(expected, boundingRectangle);
            }

            {
                var p = new PolygonGrid2DBuilder()
                        .AddPoint(0, 0)
                        .AddPoint(0, 6)
                        .AddPoint(3, 6)
                        .AddPoint(3, 3)
                        .AddPoint(7, 3)
                        .AddPoint(7, 0)
                        .Build();

                var boundingRectangle = p.BoundingRectangle;
                var expected          = new RectangleGrid2D(new Vector2Int(0, 0), new Vector2Int(7, 6));

                Assert.AreEqual(expected, boundingRectangle);
            }
        }
예제 #15
0
    private RoomDescriptionGrid2D GetRoomDescription()
    {
        var roomsTemplates = new List <RoomTemplateGrid2D>();
        var doors          = new SimpleDoorModeGrid2D(doorLength: 1, cornerDistance: 2);

        System.Random rnd             = new System.Random();
        var           roomWidthArray  = Enumerable.Range(roomMinWidth, roomMaxWidth - roomMinWidth + 1).ToArray();
        var           roomHieghtArray = Enumerable.Range(roomMinHeight, roomMaxHeight - roomMinHeight + 1).ToArray();

        var transformations = new List <TransformationGrid2D>()
        {
            TransformationGrid2D.Identity
        };

        for (var i = 0; i <= numberOfRooms; i++)
        {
            var roomTemplate = new RoomTemplateGrid2D(
                PolygonGrid2D.GetRectangle(roomWidthArray.OrderBy(a => UnityEngine.Random.value).FirstOrDefault(), roomHieghtArray.OrderBy(a => UnityEngine.Random.value).FirstOrDefault()),
                doors,
                allowedTransformations: transformations);

            roomsTemplates.Add(roomTemplate);
        }

        var roomDescription = new RoomDescriptionGrid2D
                              (
            isCorridor: false,
            roomTemplates: roomsTemplates
                              );

        return(roomDescription);
    }
예제 #16
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);
        }
예제 #17
0
 private RoomTemplate GetRoomTemplate(RoomTemplateRepeatMode repeatMode, List <TransformationGrid2D> transformations = null)
 {
     return(new RoomTemplate(
                PolygonGrid2D.GetRectangle(10, 20),
                new SimpleDoorMode(1, 0),
                transformations,
                repeatMode
                ));
 }
예제 #18
0
        public void OverlapAlongLine_Rectangles_OverlapStart2()
        {
            var p1   = PolygonGrid2D.GetSquare(5);
            var p2   = PolygonGrid2D.GetRectangle(2, 3) + new Vector2Int(0, -3);
            var line = new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 10));

            var result = polygonOverlap.OverlapAlongLine(p1, p2, line);

            Assert.AreEqual(0, result.Count);
        }
예제 #19
0
        public void GetAllTransformations_ReturnsCorrectCount()
        {
            var square    = PolygonGrid2D.GetSquare(1);
            var rectangle = PolygonGrid2D.GetRectangle(1, 2);

            var transformedSquares    = square.GetAllTransformations();
            var transformedRectangles = rectangle.GetAllTransformations();

            Assert.That(transformedSquares.Count(), Is.EqualTo(8));
            Assert.That(transformedRectangles.Count(), Is.EqualTo(8));
        }
예제 #20
0
        public void Rectangle_TwoOverlap()
        {
            var polygon           = PolygonGrid2D.GetRectangle(3, 5);
            var mode              = new SimpleDoorMode(1, 2);
            var doorPositions     = simpleModeHandler.GetDoorPositions(polygon, mode);
            var expectedPositions = new List <DoorLine>()
            {
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 2), new Vector2Int(0, 2), OrthogonalLineGrid2D.Direction.Top), 1),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(3, 3), new Vector2Int(3, 3), OrthogonalLineGrid2D.Direction.Bottom), 1),
            };

            Assert.IsTrue(doorPositions.SequenceEqualWithoutOrder(expectedPositions));
        }
예제 #21
0
        public void Rotate_Rectangle_ReturnsRotated()
        {
            var polygon        = PolygonGrid2D.GetRectangle(2, 5);
            var rotatedPolygon = polygon.Rotate(270);
            var expectedPoints = new List <Vector2Int>()
            {
                new Vector2Int(0, 0),
                new Vector2Int(-5, 0),
                new Vector2Int(-5, 2),
                new Vector2Int(0, 2),
            };

            Assert.IsTrue(expectedPoints.SequenceEqual(rotatedPolygon.GetPoints()));
        }
예제 #22
0
        public void OverlapAlongLine_Rectangles_OverlapEnd()
        {
            var p1   = PolygonGrid2D.GetSquare(5);
            var p2   = PolygonGrid2D.GetRectangle(2, 3) + new Vector2Int(0, 8);
            var line = new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 10));

            var result   = polygonOverlap.OverlapAlongLine(p1, p2, line);
            var expected = new List <Tuple <Vector2Int, bool> >()
            {
                Tuple.Create(new Vector2Int(0, 4), true),
            };

            Assert.IsTrue(expected.SequenceEqual(result));
        }
예제 #23
0
        public void Rectangle_LengthZero()
        {
            var polygon           = PolygonGrid2D.GetRectangle(3, 5);
            var mode              = new SimpleDoorMode(0, 0);
            var doorPositions     = simpleModeHandler.GetDoorPositions(polygon, mode);
            var expectedPositions = new List <DoorLine>()
            {
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(0, 5)), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(0, 5), new Vector2Int(3, 5)), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(3, 5), new Vector2Int(3, 0)), 0),
                new DoorLine(new OrthogonalLineGrid2D(new Vector2Int(3, 0), new Vector2Int(0, 0)), 0),
            };

            Assert.IsTrue(doorPositions.SequenceEqualWithoutOrder(expectedPositions));
        }
예제 #24
0
        public void GetPoints_Rectangle()
        {
            var polygon        = new Polygon2D(PolygonGrid2D.GetRectangle(6, 10));
            var expectedPoints = new List <Vector2Int>()
            {
                new Vector2Int(0, 0),
                new Vector2Int(0, 10),
                new Vector2Int(6, 10),
                new Vector2Int(6, 0),
            };

            var points = polygon.GetCornerPoints();

            Assert.That(points, Is.EquivalentTo(expectedPoints));
        }
예제 #25
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,
            });
        }
예제 #26
0
        public MapDescription <int> GetMapDescription()
        {
            // Prepare room templates
            var doorMode = new SimpleDoorMode(1, 1);

            var squareRoom = new RoomTemplate(
                new PolygonGrid2DBuilder()
                .AddPoint(0, 0)
                .AddPoint(0, 8)
                .AddPoint(8, 8)
                .AddPoint(8, 0)
                .Build(),
                doorMode
                );

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

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

            // Create map description
            var mapDescription = new MapDescription <int>();

            // Add rooms
            mapDescription.AddRoom(0, basicRoomDescription);
            mapDescription.AddRoom(1, basicRoomDescription);
            mapDescription.AddRoom(2, basicRoomDescription);
            mapDescription.AddRoom(3, basicRoomDescription);

            // Add connections
            mapDescription.AddConnection(0, 1);
            mapDescription.AddConnection(0, 3);
            mapDescription.AddConnection(1, 2);
            mapDescription.AddConnection(2, 3);

            // Add room shapes
            return(mapDescription);
        }
예제 #27
0
        public void DoOverlap_NonOverlappingPolygons_ReturnsFalse()
        {
            {
                var p1 = GetLShape().Rotate(90);
                var p2 = PolygonGrid2D.GetSquare(3);

                Assert.IsFalse(polygonOverlap.DoOverlap(p1, new Vector2Int(0, 0), p2, new Vector2Int(0, 0)));
            }

            {
                var p1 = GetPlusShape();
                var p2 = PolygonGrid2D.GetRectangle(2, 3);

                Assert.IsFalse(polygonOverlap.DoOverlap(p1, new Vector2Int(0, 0), p2, new Vector2Int(4, 4)));
            }
        }
예제 #28
0
        private List <RoomConfiguration> GetConfigurations(Dictionary <TRoom, Vector2Int> positions)
        {
            var configurations = new List <RoomConfiguration>();
            var outline        = PolygonGrid2D.GetRectangle(7, 7);
            var scale          = 9;

            foreach (var pair in positions)
            {
                var room     = pair.Key;
                var position = pair.Value;

                configurations.Add(new RoomConfiguration(room, scale * position, outline));
            }

            return(configurations);
        }
예제 #29
0
        public void GetAllPoints_Rectangle()
        {
            var polygon        = new Polygon2D(PolygonGrid2D.GetRectangle(6, 10));
            var expectedPoints = new List <Vector2Int>();

            for (int i = 0; i <= 6; i++)
            {
                for (int j = 0; j <= 10; j++)
                {
                    expectedPoints.Add(new Vector2Int(i, j));
                }
            }

            var points = polygon.GetAllPoints();

            Assert.That(points, Is.EquivalentTo(expectedPoints));
        }
예제 #30
0
    private RoomDescriptionGrid2D GetCorridorDescription()
    {
        var corridorOutline = PolygonGrid2D.GetRectangle(4, 3);
        var corridorDoors   = new ManualDoorModeGrid2D(new List <DoorGrid2D>()
        {
            new DoorGrid2D(new Edgar.Geometry.Vector2Int(0, 1), new Edgar.Geometry.Vector2Int(0, 2)),
            new DoorGrid2D(new Edgar.Geometry.Vector2Int(4, 1), new Edgar.Geometry.Vector2Int(4, 2))
        }
                                                       );
        var corridorRoomTemplate = new RoomTemplateGrid2D(
            corridorOutline,
            corridorDoors,
            allowedTransformations: new List <TransformationGrid2D>()
        {
            TransformationGrid2D.Identity,
            TransformationGrid2D.Rotate90
        },
            name: "corridorRoomTemplate"
            );

        var corridorRoomTemplateLonger = new RoomTemplateGrid2D(
            PolygonGrid2D.GetRectangle(5, 2),
            new ManualDoorModeGrid2D(new List <DoorGrid2D>()
        {
            new DoorGrid2D(new Edgar.Geometry.Vector2Int(0, 1), new Edgar.Geometry.Vector2Int(0, 2)),
            new DoorGrid2D(new Edgar.Geometry.Vector2Int(5, 1), new Edgar.Geometry.Vector2Int(5, 2))
        }
                                     ),
            allowedTransformations: new List <TransformationGrid2D>()
        {
            TransformationGrid2D.Identity,
            TransformationGrid2D.Rotate90
        },
            name: "corridorRoomTemplateLonger"
            );

        var corridorRoomDescription = new RoomDescriptionGrid2D(
            isCorridor: true,
            roomTemplates: new List <RoomTemplateGrid2D>()
        {
            corridorRoomTemplate, corridorRoomTemplateLonger
        }
            );

        return(corridorRoomDescription);
    }