Пример #1
0
        public void TestCellAutoConnectivityAndEnclosure()
        {
            var random = new StandardGenerator();
            var map    = new ArrayMap <bool>(80, 50);

            for (int i = 0; i < 500; i++)
            {
                QuickGenerators.GenerateCellularAutomataMap(map, random, 40, 7, 4);

                // Ensure it's connected
                var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList();
                Assert.AreEqual(1, areas.Count);

                // Ensure it's enclosed
                for (int x = 0; x < map.Width; x++)
                {
                    Assert.AreEqual(false, map[x, 0]);
                    Assert.AreEqual(false, map[x, map.Height - 1]);
                }
                for (int y = 0; y < map.Height; y++)
                {
                    Assert.AreEqual(false, map[0, y]);
                    Assert.AreEqual(false, map[map.Width - 1, y]);
                }
            }
        }
Пример #2
0
        public static int[] GetStats(int height, int width, int tries, ArrayMap <bool> pattern)
        {
            StandardGenerator random = new StandardGenerator();

            var wMap = new ArrayMap <bool>(height, width);

            int[] hits = new int[tries];

            for (int i = 0; i < tries; i++)
            {
                QuickGenerators.GenerateCellularAutomataMap(wMap, random);

                var pMap = new ArrayMap <bool>(height, width);

                while (TryGetFirstPatternMatch(wMap, pMap, pattern, out Coord coord))
                {
                    foreach (var pos in pattern.Positions())
                    {
                        pMap[pos.X + coord.X, pos.Y + coord.Y] = true;
                    }

                    hits[i] += 1;
                }
            }

            return(hits);
        }
Пример #3
0
        public void ManualTestCellAutoGen()
        {
            var random = new StandardGenerator();
            var map    = new ArrayMap <bool>(80, 50);

            QuickGenerators.GenerateCellularAutomataMap(map, random, 40, 7, 4);

            displayMap(map);

            // TODO: Asserts
        }
Пример #4
0
        public override void _Ready()
        {
            var terrain = new ArrayMap <bool>(40, 40);

            MapHelper.TileMap = this;
            MapHelper.FogMap  = GetParent().GetNode <TileMap>("FogMap");

            QuickGenerators.GenerateCellularAutomataMap(terrain);

            var map = new GoRogue.GameFramework.Map(
                width: terrain.Width,
                height: terrain.Height,
                numberOfEntityLayers: 1,
                distanceMeasurement: Distance.CHEBYSHEV
                );

            foreach (var pos in terrain.Positions())
            {
                MapHelper.FogMap.SetCell(pos.X, pos.Y, 0);
                if (terrain[pos])
                {
                    SetCell(pos.X, pos.Y, 0);
                    map.SetTerrain(TerrainFactory.Floor(pos));
                    MapHelper.EmptyTiles.Add(new Vector2(pos.X, pos.Y));
                }
                else // Wall
                {
                    map.SetTerrain(TerrainFactory.Wall(pos));
                    SetCell(pos.X, pos.Y, 1);
                }
            }

            var playerScene = GD.Load <PackedScene>("res://entities/Player.tscn");
            var player      = playerScene.Instance() as Player;

            map.AddEntity(player);
            MapHelper.TileMap.AddChild(player);

            var enemyScene = GD.Load <PackedScene>("res://entities/Enemy.tscn");

            foreach (var e in Enumerable.Range(0, 10))
            {
                var enemy = enemyScene.Instance() as Enemy;
                map.AddEntity(enemy);
                MapHelper.TileMap.AddChild(enemy);
            }

            MapHelper.CurrentMap = map;

            GD.Print("Number of entities: " + MapHelper.CurrentMap.Entities.Count);
            GD.Print("Number of children: " + GetChildCount());
        }
Пример #5
0
        public Map(IGenerator dungeonRandom, int width, int height, Adventure adventure, bool useTestMap = false)
        {
            Width     = width;
            Height    = height;
            Adventure = adventure;

            var wMap = new ArrayMap <bool>(width, height);

            // creating map here
            if (useTestMap)
            {
                TestMap(wMap);
            }
            else
            {
                //QuickGenerators.GenerateRandomRoomsMap(wMap, dungeonRandom, 15, 5, 15, 50);
                QuickGenerators.GenerateCellularAutomataMap(wMap, dungeonRandom);
            }

            WalkabilityMap = wMap;
            ExplorationMap = new ArrayMap <int>(width, height);
            EntityMap      = new ArrayMap <AdventureEntityContainer>(width, height);
            TileMap        = new ArrayMap <Tile>(width, height);
            Entities       = new List <AdventureEntity>();
            var resMap = new ArrayMap <bool>(width, height);

            foreach (var pos in wMap.Positions())
            {
                // build up Entity Map, not necessary and really slow on big maps
                //EntityMap[i,j] = new AdventureEntityContainer();

                if (wMap[pos.X, pos.Y])
                {
                    //ExplorationMap[i, j] = 1;
                    _walkableTiles++;
                    resMap[pos.X, pos.Y]  = true;
                    TileMap[pos.X, pos.Y] = new StoneTile(this, new Coord(pos.X, pos.Y));
                }
                else
                {
                    //ExplorationMap[i, j] = -9;
                    resMap[pos.X, pos.Y]  = false;
                    TileMap[pos.X, pos.Y] = new StoneWall(this, new Coord(pos.X, pos.Y));
                }
            }

            FovMap = new FOV(resMap);

            Locations = CreateMapLocations(wMap, 9);

            ExpectedFovNum = new int[width, height];
        }
Пример #6
0
        public void ApplyOverlayTest()
        {
            var map = new ArrayMap <bool>(100, 100);

            QuickGenerators.GenerateCellularAutomataMap(map);

            var duplicateMap = new ArrayMap <bool>(map.Width, map.Height);

            duplicateMap.ApplyOverlay(map);

            foreach (var pos in map.Positions())
            {
                Assert.AreEqual(map[pos], duplicateMap[pos]);
            }
        }
Пример #7
0
        private static void Pathing()
        {
            /* AStar */
            var timeAStar     = PathingTests.TimeForAStar(Runner.MAP_WIDTH, Runner.MAP_HEIGHT, Runner.ITERATIONS_FOR_TIMING);
            var timeFastAStar = PathingTests.TimeForFastAStar(Runner.MAP_WIDTH, Runner.MAP_HEIGHT, Runner.ITERATIONS_FOR_TIMING);

            Console.WriteLine($"Time for {Runner.ITERATIONS_FOR_TIMING} paths, on {Runner.MAP_WIDTH}x{Runner.MAP_HEIGHT} map:");
            Console.WriteLine($"\tAStar    : {timeAStar}");
            Console.WriteLine($"\tFastAStar: {timeFastAStar}");

            /* Single-Goal GoalMap */
            var map = new ArrayMap <bool>(Runner.MAP_WIDTH, Runner.MAP_HEIGHT);

            QuickGenerators.GenerateCellularAutomataMap(map);
            Coord goal = map.RandomPosition(true);

            var timeGoalMap = PathingTests.TimeForGoalMap(map, goal.Yield(), Runner.ITERATIONS_FOR_TIMING);
            var timeFleeMap = PathingTests.TimeForFleeMap(map, goal.Yield(), Runner.ITERATIONS_FOR_TIMING);

            Console.WriteLine();
            Console.WriteLine($"Time to calculate single-source goal map on {Runner.MAP_WIDTH}x{Runner.MAP_HEIGHT} map {Runner.ITERATIONS_FOR_TIMING} times:");
            Console.WriteLine($"\tGoal-Map    : {timeGoalMap}");
            Console.WriteLine($"\tFlee-Map    : {timeFleeMap}");

            /* Multi-Goal GoalMap */
            var goals = new List <Coord>();

            for (int i = 0; i < Runner.NUM_GOALS; i++)
            {
                goals.Add(map.RandomPosition(true));
            }

            var timeMGoalMap = PathingTests.TimeForGoalMap(map, goals, Runner.ITERATIONS_FOR_TIMING);
            var timeMFleeMap = PathingTests.TimeForFleeMap(map, goals, Runner.ITERATIONS_FOR_TIMING);

            Console.WriteLine();
            Console.WriteLine($"Time to calculate multi-source goal map on {Runner.MAP_WIDTH}x{Runner.MAP_HEIGHT} map {Runner.ITERATIONS_FOR_TIMING} times:");
            Console.WriteLine($"\tGoal-Map    : {timeMGoalMap}");
            Console.WriteLine($"\tFlee-Map    : {timeMFleeMap}");
        }
Пример #8
0
        public static Map Build(int width, int height, string id, GameContext context, MapType typ)
        {
            var baseMap = new ArrayMap <Terrain>(width, height);
            var trans   = new TerrainTranslator(baseMap, Swatch.StoneWall, Swatch.StoneFloor);

            List <Coord> doors = new List <Coord>();

            switch (typ)
            {
            case MapType.DUNGEON:
                var dunResult = QuickGenerators.GenerateDungeonMazeMap(trans, context.RNG, 10, 50, 5, 21);
                foreach (var(room, connectors) in dunResult)
                {
                    foreach (var side in connectors)
                    {
                        foreach (var door in side)
                        {
                            doors.Add(door);
                        }
                    }
                }
                break;

            case MapType.CAVES:
                var caveResult = QuickGenerators.GenerateCellularAutomataMap(trans, context.RNG);
                break;
            }

            var fullMap = Map.CreateMap(baseMap, 4, Distance.CHEBYSHEV);

            foreach (var newDoorSpot in doors)
            {
                fullMap.AddEntity(new Door(newDoorSpot, false));
            }
            context.RegisterMap(id, fullMap);
            return(fullMap);
        }
Пример #9
0
        public static Map Build(MapType mt, int width, int height, string id, Color wallColor, Color floorColor)
        {
            var baseMap = new ArrayMap <Terrain>(width, height);
            var trans   = new TerrainTranslator(baseMap, wallColor, floorColor);

            List <Coord> doors = new List <Coord>();

            switch (mt)
            {
            case MapType.DUNGEON:
                var dunResult = QuickGenerators.GenerateDungeonMazeMap(trans, _rng,
                                                                       MIN_ROOMS, MAX_ROOMS, ROOM_MIN_SIZE, ROOM_MAX_SIZE);
                foreach (var(room, connectors) in dunResult)
                {
                    foreach (var side in connectors)
                    {
                        foreach (var door in side)
                        {
                            doors.Add(door);
                        }
                    }
                }
                break;

            case MapType.CAVES:
                var caveResult = QuickGenerators.GenerateCellularAutomataMap(trans, _rng);
                break;
            }

            var fullMap = Map.CreateMap(baseMap, 4, Distance.CHEBYSHEV);

            /*
             * foreach (var newDoorSpot in doors)
             *  fullMap.AddEntity(new Door(newDoorSpot, false))
             */
            return(fullMap);
        }