コード例 #1
0
        public void GetConfigurationSpaceOverCorridor_RoomShapesThatCannotBeCorrectlyConnected()
        {
            var roomShape1     = PolygonGrid2D.GetSquare(5);
            var roomDoorsMode1 = new SimpleDoorMode(1, 0);

            var roomShape2 = new PolygonGrid2DBuilder()
                             .AddPoint(0, 1)
                             .AddPoint(0, 2)
                             .AddPoint(2, 2)
                             .AddPoint(2, 0)
                             .AddPoint(1, 0)
                             .AddPoint(1, 1)
                             .Build();
            var roomDoorsMode2 = new ManualDoorMode(new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(1, 1), new Vector2Int(0, 1)),
            });

            var corridor          = PolygonGrid2D.GetSquare(2);
            var corridorDoorsMode = 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)),
            });

            var configurationSpace = generator.GetConfigurationSpaceOverCorridor(roomShape2, roomDoorsMode2, roomShape1,
                                                                                 roomDoorsMode1, corridor, corridorDoorsMode);

            Assert.That(configurationSpace.Lines.SelectMany(x => x.GetPoints()), Is.Empty);
        }
コード例 #2
0
        public static RoomTemplate ToOldRoomTemplate(this RoomTemplateGrid2D roomTemplate)
        {
            var       doorMode    = roomTemplate.Doors;
            IDoorMode oldDoorMode = null;

            if (roomTemplate.RepeatMode == null)
            {
                throw new NotSupportedException("Null repeat mode is currently not supported");
            }

            if (doorMode is SimpleDoorModeGrid2D simpleDoorMode)
            {
                if (simpleDoorMode.DoorSocket != null)
                {
                    throw new NotSupportedException("Old room templates support only null sockets");
                }

                oldDoorMode = new SimpleDoorMode(simpleDoorMode.DoorLength, simpleDoorMode.CornerDistance);
            }
            else if (doorMode is ManualDoorModeGrid2D manualDoorMode)
            {
                if (manualDoorMode.Doors.Any(x => x.Socket != null))
                {
                    throw new NotSupportedException("Old room templates support only null sockets");
                }

                oldDoorMode = new ManualDoorMode(manualDoorMode.Doors.Select(x => new OrthogonalLineGrid2D(x.From, x.To)).ToList());
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            return(new RoomTemplate(roomTemplate.Outline, oldDoorMode, roomTemplate.AllowedTransformations, roomTemplate.RepeatMode.Value, roomTemplate.Name));
        }
コード例 #3
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));
        }
コード例 #4
0
        public void GetConfigurationSpaceOverCorridor_SquareRoomLShapedCorridor()
        {
            var roomShape     = PolygonGrid2D.GetSquare(5);
            var roomDoorsMode = new SimpleDoorMode(1, 0);

            var corridor = new PolygonGrid2DBuilder()
                           .AddPoint(0, 1)
                           .AddPoint(0, 2)
                           .AddPoint(2, 2)
                           .AddPoint(2, 0)
                           .AddPoint(1, 0)
                           .AddPoint(1, 1)
                           .Build();

            var corridorDoorsMode = new ManualDoorMode(new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(0, 1), new Vector2Int(0, 2)),
                new OrthogonalLineGrid2D(new Vector2Int(2, 0), new Vector2Int(1, 0)),
            });

            var expectedLines = new List <OrthogonalLineGrid2D>()
            {
                new OrthogonalLineGrid2D(new Vector2Int(-6, 2), new Vector2Int(-6, 6)), // Left side
                new OrthogonalLineGrid2D(new Vector2Int(-5, 2), new Vector2Int(-5, 6)),
                new OrthogonalLineGrid2D(new Vector2Int(-6, 6), new Vector2Int(-2, 6)), // Top side
                new OrthogonalLineGrid2D(new Vector2Int(-6, 5), new Vector2Int(-2, 5)),
                new OrthogonalLineGrid2D(new Vector2Int(2, -6), new Vector2Int(6, -6)), // Bottom side
                new OrthogonalLineGrid2D(new Vector2Int(2, -5), new Vector2Int(6, -5)),
                new OrthogonalLineGrid2D(new Vector2Int(5, -2), new Vector2Int(5, -6)), // Right side
                new OrthogonalLineGrid2D(new Vector2Int(6, -2), new Vector2Int(6, -6)),
            };

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

            var configurationSpace = generator.GetConfigurationSpaceOverCorridor(roomShape, roomDoorsMode, roomShape,
                                                                                 roomDoorsMode, corridor, corridorDoorsMode);

            var configurationSpacePoints = configurationSpace
                                           .Lines
                                           .SelectMany(x => x.GetPoints())
                                           .ToList();

            Assert.That(configurationSpacePoints, Is.EquivalentTo(expectedPoints));
        }
コード例 #5
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));
            }
        }
コード例 #6
0
        public void GetConfigurationSpaceOverCorridor_SquareRoomHorizontalCorridor()
        {
            var roomShape     = PolygonGrid2D.GetSquare(5);
            var roomDoorsMode = new SimpleDoorMode(1, 0);

            var corridor          = PolygonGrid2D.GetRectangle(2, 1);
            var corridorDoorsMode = 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)),
            });

            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)),
            };

            var configurationSpace = generator.GetConfigurationSpaceOverCorridor(roomShape, roomDoorsMode, roomShape,
                                                                                 roomDoorsMode, corridor, corridorDoorsMode);

            Assert.That(configurationSpace.Lines.SelectMany(x => x.GetPoints()), Is.EquivalentTo(expectedLines.SelectMany(x => x.GetPoints())));
        }