Beispiel #1
0
        public void TestRandomRoomsGenSize()
        {
            var map = new ArrayMap <bool>(40, 40);

            QuickGenerators.GenerateRandomRoomsMap(map, 30, 4, 6, 10);

            Console.WriteLine(map.ToString(b => b ? "." : "#"));
        }
Beispiel #2
0
        public void TestDungeonGenDefaultRNG()
        {
            // default rng
            var map = new ArrayMap <bool>(100, 100);

            // Assert no exceptions are thrown
            QuickGenerators.GenerateDungeonMazeMap(map, 10, 30, 4, 9);
        }
Beispiel #3
0
        private static IMapView <double> BoxResMap(int width, int height)
        {
            var map = new ArrayMap <bool>(width, height);

            QuickGenerators.GenerateRectangleMap(map);

            return(new LambdaTranslationMap <bool, double>(map, val => val ? 0.0 : 1.0));
        }
Beispiel #4
0
        public void ManualTestRandomRoomsGen()
        {
            var random = new StandardGenerator();
            var map    = new ArrayMap <bool>(80, 50);

            QuickGenerators.GenerateRandomRoomsMap(map, random, 10, 4, 15, 5);

            displayMap(map);
            // TODO: Some assert here
        }
Beispiel #5
0
        public void LambaMapViewTest()
        {
            ArrayMap <bool> map = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(map);

            IMapView <double> lambdaMapView = new LambdaMapView <double>(map.Width, map.Height, c => map[c] ? 1.0 : 0.0);

            checkMaps(map, lambdaMapView);
        }
Beispiel #6
0
        public void LambdaTranslationMapTest()
        {
            ArrayMap <bool> map = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(map);

            var lambdaMap = new LambdaTranslationMap <bool, double>(map, b => b ? 1.0 : 0.0);

            checkMaps(map, lambdaMap);
        }
Beispiel #7
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
        }
Beispiel #8
0
        public void ManualTestDungeonMazeGen()
        {
            var random = new StandardGenerator(12345);

            var map = new ArrayMap <bool>(80, 50);

            QuickGenerators.GenerateDungeonMazeMap(map, random, minRooms: 4, maxRooms: 10, roomMinSize: 4, roomMaxSize: 7, maxTrimIterations: 20);

            displayMap(map);
            // TODO: Some assert here
        }
Beispiel #9
0
        public void ManualPrintPath()
        {
            var map = new ArrayMap <bool>(30, 30);

            QuickGenerators.GenerateRectangleMap(map);

            var pather = new AStar(map, Distance.MANHATTAN);
            var path   = pather.ShortestPath(1, 2, 5, 6);

            Console.WriteLine(path);
        }
Beispiel #10
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];
        }
Beispiel #11
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());
        }
Beispiel #12
0
        //todo temp for prototype
        private CombatMap GenerateTerrain()
        {
            var terrainMap = new ArrayMap <bool>(MapWidth, MapHeight);

            QuickGenerators.GenerateRectangleMap(terrainMap);

            var map = new CombatMap(terrainMap.Width, terrainMap.Height);

            var biome = FindObjectOfType <TravelManager>().CurrentBiome;

            var tStore = FindObjectOfType <TerrainStore>();

            var tileWeights = tStore.GetTileTypeWeights(biome);

            foreach (var position in terrainMap.Positions())
            {
                var selection = tileWeights.First().Key;

                var totalWeight = tileWeights.Values.Sum();

                var roll = Random.Range(0, totalWeight);

                foreach (var tType in tileWeights.OrderByDescending(t => t.Value))
                {
                    var weightedValue = tType.Value;

                    if (roll >= weightedValue)
                    {
                        roll -= weightedValue;
                    }
                    else
                    {
                        selection = tType.Key;
                        break;
                    }
                }

                Tile tile;
                if (IsWallTile(selection))
                {
                    tile = tStore.GetWallTile(biome, selection, position, MapWidth, MapHeight);
                }
                else
                {
                    tile = TerrainStore.GetFloorTile(biome, selection, position, MapWidth, MapHeight);
                }

                map.SetTerrain(tile);
            }

            return(map);
        }
Beispiel #13
0
        public void TestDungeonGenNonDefaultRNG()
        {
            var map = new ArrayMap <bool>(100, 100);
            // Assert no exceptions are thrown
            var gen = new XorShift128Generator();

            for (int i = 0; i < 3; i++)             // Due to Troscheutz.Random bug
            {
                gen.Next();
            }

            QuickGenerators.GenerateDungeonMazeMap(map, gen, 10, 30, 4, 9);
        }
        private void GenerateMap()
        {
            QuickGenerators.GenerateRectangleMap(isWalkable);
            var clustersLeft = NUM_CLUSTERS;

            while (clustersLeft-- > 0)
            {
                var x        = random.Next(this.width);
                var y        = random.Next(this.height);
                var numTiles = random.Next(MIN_CLUSTER_SIZE, MAX_CLUSTER_SIZE + 1);
                this.RandomWalk(x, y, numTiles, false);
            }
        }
Beispiel #15
0
        public void LambdaSettableMapViewTest()
        {
            ArrayMap <double> map = new ArrayMap <double>(10, 10);

            ArrayMap <bool> controlMap = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(controlMap);

            var settable = new LambdaSettableMapView <bool>(map.Width, map.Height, c => map[c] > 0.0, (c, b) => map[c] = b ? 1.0 : 0.0);

            QuickGenerators.GenerateRectangleMap(settable);

            checkMaps(controlMap, map);
        }
Beispiel #16
0
        public void ManualPrintFOV()
        {
            var map = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(map);

            FOV myFov = new FOV(map);

            myFov.Calculate(5, 5, 3);

            Console.WriteLine(myFov);
            Console.WriteLine();
            Console.WriteLine(myFov.ToString(3));
        }
Beispiel #17
0
        public void LambdaSettableTranslationMapTest()
        {
            ArrayMap <double> map = new ArrayMap <double>(10, 10);

            ArrayMap <bool> controlMap = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(controlMap);

            var settable = new LambdaSettableTranslationMap <double, bool>(map, d => d > 0.0, b => b ? 1.0 : 0.0);

            QuickGenerators.GenerateRectangleMap(settable);

            checkMaps(controlMap, map);
        }
Beispiel #18
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]);
            }
        }
Beispiel #19
0
        public void TestSingleAreaRect()
        {
            var map = new ArrayMap <bool>(80, 50);

            QuickGenerators.GenerateRectangleMap(map);

            var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList();

            foreach (var area in areas)
            {
                Console.WriteLine(area.Bounds);
            }

            Assert.AreEqual(1, areas.Count);
        }
Beispiel #20
0
        public void TestTwoAreaRect()
        {
            var map = new ArrayMap <bool>(80, 50);

            QuickGenerators.GenerateRectangleMap(map);

            for (int y = 0; y < 50; y++)
            {
                map[40, y] = false;
            }

            var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList();

            Assert.AreEqual(2, areas.Count);
        }
Beispiel #21
0
        public void LambdaTranslationMapTest()
        {
            ArrayMap <bool> map = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(map);

            var lambdaMap = new LambdaTranslationMap <bool, double>(map, b => b ? 1.0 : 0.0);

            checkMaps(map, lambdaMap);

            // Check other constructor.  Intentaionally "misusing" the position parameter, to make sure we ensure the position
            // parameter is correct without complicating our test case
            lambdaMap = new LambdaTranslationMap <bool, double>(map, (pos, b) => map[pos] ? 1.0 : 0.0);
            checkMaps(map, lambdaMap);
        }
Beispiel #22
0
        public static long MemorySingleLightSourceFOV(int mapWidth, int mapHeight, int lightRadius)
        {
            FOV  fov;
            long startingMem, endingMem;
            var  map = new ArrayMap <bool>(mapWidth, mapHeight);

            QuickGenerators.GenerateRectangleMap(map);

            // Start mem test
            startingMem = GC.GetTotalMemory(true);
            fov         = new FOV(map);
            fov.Calculate(5, 6, lightRadius, Radius.CIRCLE);             // Must calculate to force allocations
            endingMem = GC.GetTotalMemory(true);

            return(endingMem - startingMem);
        }
Beispiel #23
0
        private static void Main(string[] args)
        {
            Animations = new AnimationHandler();
            rand       = new Random();

            var engine = new Engine(Width, Height, "Gaserel", true, StepUpdate, Render, Animations);

            map = new Map(Width, Height, 1, Distance.MANHATTAN);
            ISettableMapView <bool> mapview = new ArrayMap <bool>(Width, Height);

            QuickGenerators.GenerateRandomRoomsMap(mapview, 20, 8, 20);
            map.ApplyTerrainOverlay(mapview, (pos, val) => val ? TerrainFactory.Floor(pos) : TerrainFactory.Wall(pos));

            _gasLayers = new List <GasInfo>()
            {
                new GasInfo(Width, Height, Color.Red),
                new GasInfo(Width, Height, Color.Blue),
                new GasInfo(Width, Height, Color.Green),
                new GasInfo(Width, Height, Color.Purple)
            };

            Coord p1 = map.Terrain.RandomPosition((_, tile) => tile.IsWalkable);
            var   e1 = new GameObject(p1, 1, null);

            e1.AddComponent(new DrawComponent('%', Color.Red));
            e1.AddComponent(new EmitComponent(_gasLayers[0], 100, 6, 100));
            map.AddEntity(e1);

            Coord p2 = map.Terrain.RandomPosition((_, tile) => tile.IsWalkable);
            var   e2 = new GameObject(p2, 1, null);

            e2.AddComponent(new DrawComponent('%', Color.Blue));
            e2.AddComponent(new EmitComponent(_gasLayers[1], 200, -100, -10));
            map.AddEntity(e2);

            Coord p3 = map.Terrain.RandomPosition((_, tile) => tile.IsWalkable);

            e3 = new GameObject(p3, 1, null);
            e3.AddComponent(new DrawComponent('@', Color.White));
            e3.IsWalkable = false;

            map.AddEntity(e3);

            engine.Start();
            engine.Run();
        }
        public static TimeSpan TimeForRandomRooms(int mapWidth, int mapHeight, int iterations, int maxRooms, int roomMinSize, int roomMaxSize)
        {
            var s = new Stopwatch();
            // For caching
            var mapToGenerate = new ArrayMap <bool>(mapWidth, mapHeight);

            QuickGenerators.GenerateRandomRoomsMap(mapToGenerate, maxRooms, roomMinSize, roomMaxSize);

            s.Start();
            for (int i = 0; i < iterations; i++)
            {
                mapToGenerate = new ArrayMap <bool>(mapWidth, mapHeight);
                QuickGenerators.GenerateRandomRoomsMap(mapToGenerate, maxRooms, roomMinSize, roomMaxSize);
            }
            s.Stop();

            return(s.Elapsed);
        }
Beispiel #25
0
        public static ExampleMap GenerateDungeon(int width, int height)
        {
            // Same size as screen, but we set up to center the camera on the player so expanding beyond this should work fine with no other changes.
            var map = new ExampleMap(width, height);

            // Generate map via GoRogue, and update the real map with appropriate terrain.
            var tempMap = new ArrayMap <bool>(map.Width, map.Height);

            QuickGenerators.GenerateDungeonMazeMap(tempMap, minRooms: 10, maxRooms: 20, roomMinSize: 5, roomMaxSize: 11);
            map.ApplyTerrainOverlay(tempMap, SpawnTerrain);

            Coord posToSpawn;

            // Spawn a few minotaurs
            for (int i = 0; i < 2; i++)
            {
                posToSpawn = map.WalkabilityView.RandomPosition(true); // Get a location that is walkable
                var minotaur = new Minotaur(posToSpawn, map);
                map.AddEntity(minotaur);
            }

            // Spawn a few goblins
            for (int i = 0; i < 8; i++)
            {
                posToSpawn = map.WalkabilityView.RandomPosition(true); // Get a location that is walkable
                var goblin = new Goblin(posToSpawn, map);
                map.AddEntity(goblin);
            }

            // Spawn a few rats
            for (int i = 0; i < 4; i++)
            {
                posToSpawn = map.WalkabilityView.RandomPosition(true); // Get a location that is walkable
                var rat = new Rat(posToSpawn, map);
                map.AddEntity(rat);
            }

            // Spawn player
            posToSpawn = map.WalkabilityView.RandomPosition(true);
            map.ControlledGameObject = new Player(posToSpawn);
            map.AddEntity(map.ControlledGameObject);

            return(map);
        }
Beispiel #26
0
    public void GenerateMap()
    {
        var tempMap = new ArrayMap <bool>(50, 50);

        //QuickGenerators.GenerateRectangleMap(tempMap);
        QuickGenerators.GenerateRandomRoomsMap(tempMap, 20, 5, 12);
        Map = new Map(50, 50, 1, Distance.CHEBYSHEV);

        Map.ObjectMoved += OnObjectMoved;

        foreach (var position in tempMap.Positions())
        {
            if (tempMap[position])
            {
                Map.SetTerrain(new FloorTerrain(position));
            }
            else
            {
                Map.SetTerrain(new WallTerrain(position));
            }
        }

        // instance a player
        var playerInstance = GD.Load <PackedScene>("res://Characters/Player/Player.tscn").Instance() as Player;

        GetTree().Root.GetNode("Game").AddChild(playerInstance);
        playerInstance.Position        = Map.WalkabilityView.RandomPosition(true);
        playerInstance.Moved          += OnPlayerMoved;
        GameController.Instance.Player = playerInstance;
        AddCharacter(playerInstance);

        // generate monsters
        for (var i = 0; i < _numMonsters; ++i)
        {
            var skeleman = GD.Load <PackedScene>("res://Characters/Monsters/Skeleman.tscn").Instance() as Monster;
            GetTree().Root.GetNode("Game").AddChild(skeleman);
            skeleman.Position = Map.WalkabilityView.RandomPosition(true);
            AddCharacter(skeleman);
            Monsters.Add(skeleman);
        }

        Map.CalculateFOV(playerInstance.Position, playerInstance.FOVRadius, Radius.DIAMOND);
        Draw();
    }
Beispiel #27
0
        public void FOVBooleanOutput()
        {
            var map = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(map);

            var fov = new FOV(map);

            fov.Calculate(5, 5, 3);

            Console.WriteLine("FOV for reference:");
            Console.WriteLine(fov.ToString(2));

            foreach (var pos in fov.Positions())
            {
                bool inFOV = fov[pos] != 0.0;
                Assert.AreEqual(inFOV, fov.BooleanFOV[pos]);
            }
        }
Beispiel #28
0
        public void TestMazeGenConnectivityAndEnclosure()
        {
            var map = new ArrayMap <bool>(80, 50);

            try
            {
                var random = new StandardGenerator();

                for (int i = 0; i < 1500; i++)
                {
                    QuickGenerators.GenerateDungeonMazeMap(map, random, minRooms: 10, maxRooms: 20, roomMinSize: 4, roomMaxSize: 15);

                    // Ensure it's connected
                    var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList();
                    if (areas.Count != 1)
                    {
                        Console.WriteLine($"Map attempt {i + 1}/500 failed, had {areas.Count} areas: ");
                        displayMapAreas(map, areas);
                    }

                    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]);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Map attempt failed with exception on map: ");
                displayMapAreas(map, MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList());
                throw e;
            }
        }
Beispiel #29
0
        public static TimeSpan TimeForAStar(int mapWidth, int mapHeight, int iterations)
        {
            var s = new Stopwatch();

            var map = new ArrayMap <bool>(mapWidth, mapHeight);

            QuickGenerators.GenerateRectangleMap(map);

            var pather = new AStar(map, Distance.CHEBYSHEV);
            var path   = pather.ShortestPath(START, END);           // Cache warmup

            s.Start();
            for (int i = 0; i < iterations; i++)
            {
                path = pather.ShortestPath(START, END);
            }
            s.Stop();

            return(s.Elapsed);
        }
Beispiel #30
0
    public void Generate(int width, int height)
    {
        var terrainMap = new ArrayMap2D <bool>(width, height);

        // QuickGenerators.GenerateRectangleMap(terrainMap);
        QuickGenerators.GenerateRandomRoomsMap(terrainMap, 20, 7, 12);

        Data = new Map(terrainMap.Width, terrainMap.Height, 1, Distance.CHEBYSHEV);

        foreach (var position in terrainMap.Positions())
        {
            if (terrainMap[position])
            {
                var floorTile = Instantiate(_floorTile);
                floorTile.Init(map: Data, tilemap: Terrain, position, isWalkable: true, isTransparent: true);
            }
            else
            {
                var wallTile = Instantiate(_wallTile);
                wallTile.Init(map: Data, tilemap: Terrain, position, isWalkable: false, isTransparent: false);
            }
        }

        // spawn some monsters
        for (var i = 0; i < 30; i++)
        {
            var randomPos = Data.WalkabilityView.RandomPosition(true);
            var monster   = Instantiate(_monsterPrefab);
            monster.Init(randomPos, Data);
        }

        // spawn the player
        var playerPrefab = Resources.Load <Player>("Actors/Player");

        Player = Instantiate(playerPrefab);
        var randomStartingPos = Data.WalkabilityView.RandomPosition(true);

        Player.Init(randomStartingPos, Data);

        UpdatePlayerFOV();
    }