Ejemplo n.º 1
0
        public static MapData GenerateFloor(uint floorNumber, int widthInTiles, int heightInTiles)
        {
            // Generate a walkable map, complete with stairs down

            var isWalkableMap = new ArrayMap <bool>(widthInTiles, heightInTiles);

            CellularAutomataGenerator.Generate(isWalkableMap);

            // Randomly positioned on a ground tile! True = walkable
            var playerPosition = isWalkableMap.RandomPosition(true);

            var stairsDownPosition = playerPosition;

            while (Math.Abs(playerPosition.X - stairsDownPosition.X) + Math.Abs(playerPosition.Y - stairsDownPosition.Y) <= MinimumPlayerStairsDistance)
            {
                stairsDownPosition = isWalkableMap.RandomPosition(true);
            }

            System.Console.WriteLine($"Stairs are at {stairsDownPosition}");
            var mapData = new MapData()
            {
                Map = isWalkableMap, PlayerPosition = playerPosition, StairsDownPosition = stairsDownPosition
            };

            return(mapData);
        }
Ejemplo n.º 2
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
            {
                //RandomRoomsGenerator.Generate(wMap, dungeonRandom, 15, 5, 15, 50);
                CellularAutomataGenerator.Generate(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 <double>(width, height);

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    // build up Entity Map, not necessary and really slow on big maps
                    //EntityMap[i,j] = new AdventureEntityContainer();

                    if (wMap[i, j])
                    {
                        //ExplorationMap[i, j] = 1;
                        _walkableTiles++;
                        TileMap[i, j] = new StoneTile(this, Coord.Get(i, j));
                    }
                    else
                    {
                        //ExplorationMap[i, j] = -9;
                        resMap[i, j]  = 1;
                        TileMap[i, j] = new StoneWall(this, Coord.Get(i, j));
                    }
                }
            }
            FovMap = new FOV(resMap);

            Locations = CreateMapLocations(wMap, 9);

            ExpectedFovNum = new int[width, height];
        }
Ejemplo n.º 3
0
        private void aStarMatches(Distance distanceCalc)
        {
            var map = new ArrayMap <bool>(MAP_WIDTH, MAP_HEIGHT);

            CellularAutomataGenerator.Generate(map);
            var graphTuple = initGraph(map, distanceCalc);

            var pather        = new AStar(map, distanceCalc);
            var controlPather = new CA.AStar(graphTuple.Graph);

            controlPather.ChoosenHeuristic = distanceHeuristic(distanceCalc);

            for (int i = 0; i < ITERATIONS; i++)
            {
                Coord start = Coord.Get(SingletonRandom.DefaultRNG.Next(map.Width - 1), SingletonRandom.DefaultRNG.Next(map.Height - 1));
                while (!map[start])
                {
                    start = Coord.Get(SingletonRandom.DefaultRNG.Next(map.Width - 1), SingletonRandom.DefaultRNG.Next(map.Height - 1));
                }

                Coord end = Coord.Get(SingletonRandom.DefaultRNG.Next(map.Width - 1), SingletonRandom.DefaultRNG.Next(map.Height - 1));
                while (end == start || !map[end])
                {
                    end = Coord.Get(SingletonRandom.DefaultRNG.Next(map.Width - 1), SingletonRandom.DefaultRNG.Next(map.Height - 1));
                }

                var path1 = pather.ShortestPath(start, end);
                controlPather.SearchPath(graphTuple.Nodes[start.X, start.Y], graphTuple.Nodes[end.X, end.Y]);
                var path2 = controlPather.PathByNodes;

                if (path2.Length != path1.LengthWithStart)
                {
                    Console.WriteLine($"Error: Control got {path2.Length}, but custom AStar got {path1.LengthWithStart}");
                    Console.WriteLine("Control: ");
                    Utility.PrintHightlightedPoints(map, Utility.ToCoords(path2));
                    Console.WriteLine("AStar  :");
                    Utility.PrintHightlightedPoints(map, path1.StepsWithStart);
                }

                bool lengthGood = (path1.LengthWithStart <= path2.Length);
                Assert.AreEqual(true, lengthGood);
                Assert.AreEqual(path1.Start, start);
                Assert.AreEqual(path1.End, end);
                checkWalkable(path1, map);
                checkAdjacency(path1, distanceCalc);
            }
        }
Ejemplo n.º 4
0
        private static void Main(string[] args)
        {
            var gen = new CellularAutomataGenerator();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');

                int[] values =
                {
                    100, // Width
                    100, // Height
                    45,  // Alive
                    5,   // Birth
                    4,   // Survival
                    5    // Iterations
                };

                int[] otherGoodConfig =
                {
                    100,
                    100,
                    30,
                    6,
                    5,
                    5
                };

                for (int i = 0; i < input.Length && i < values.Length; i++)
                {
                    int prevVal = values[i];
                    if (!Int32.TryParse(input[i], out values[i]))
                    {
                        values[i] = prevVal;
                    }
                }

                gen.Generate(values[0], values[1], values[2], values[3], values[4], values[5]).SaveToImageFile();
            }
        }
Ejemplo n.º 5
0
        private static void Pathing()
        {
            /* AStar */
            var timeAStar = PathingTests.TimeForAStar(Runner.MAP_WIDTH, Runner.MAP_HEIGHT, Runner.ITERATIONS_FOR_TIMING);

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

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

            CellularAutomataGenerator.Generate(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}");
        }