예제 #1
0
        public static void Main(string[] args)
        {
            var sw = new Stopwatch();

            sw.Start();

            const int NumLevels = 800;

            var numThreads      = Environment.ProcessorCount;
            var levelsPerThread = NumLevels / numThreads;

            var seed = uint.Parse(args[0]);

            Console.WriteLine("The random seed is: {0}", seed);

            var levelSettings = new LevelSettings(maxRooms: 99, tileDim: 50, restWidMax: 8, widMin: 2, roomInsertionAttempts: 50000);

            var levels = Enumerable.Range(0, numThreads).AsParallel().SelectMany(threadId =>
            {
                var threadSeed = (uint)(seed * (threadId + 1) * (threadId + 1));
                Console.WriteLine("The seed for thread {0} is: {1}", threadId + 1, threadSeed);
                return(new LevelMaker(threadSeed).MakeLevels(levelSettings).Take(levelsPerThread));
            });

            var bestLevel = levels.OrderByDescending(x => x.NumberOfRooms).First();

            Console.WriteLine(bestLevel);
            Console.WriteLine((int)Math.Round(sw.Elapsed.TotalMilliseconds));
        }
예제 #2
0
        public IEnumerable <Level> MakeLevels(LevelSettings settings)
        {
            while (true)
            {
                var lev = new Level(settings.MaxRooms, settings.TileDim);

                int roomCount = 0;
                for (int attempt = 0; attempt < settings.RoomInsertionAttempts; attempt++)
                {
                    var x = _rand.Next() % settings.TileDim;
                    var y = _rand.Next() % settings.TileDim;
                    var w = _rand.Next() % settings.RestWidMax + settings.WidMin;
                    var h = _rand.Next() % settings.RestWidMax + settings.WidMin;

                    if (x + w >= settings.TileDim || y + h >= settings.TileDim || x == 0 || y == 0)
                    {
                        continue;
                    }
                    var room = new Room {
                        X = x, Y = y, W = w, H = h
                    };
                    if (lev.TryAddRoom(room))
                    {
                        if (++roomCount == settings.MaxRooms)
                        {
                            break;
                        }
                    }
                }

                yield return(lev);
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var sw = new Stopwatch();
            sw.Start();

            const int NumLevels = 800;

            var numThreads = Environment.ProcessorCount;
            var levelsPerThread = NumLevels / numThreads;

            var seed = uint.Parse(args[0]);
            Console.WriteLine("The random seed is: {0}", seed);

            var levelSettings = new LevelSettings(maxRooms: 99, tileDim: 50, restWidMax: 8, widMin: 2, roomInsertionAttempts: 50000);

            var levels = Enumerable.Range(0, numThreads).AsParallel().SelectMany(threadId =>
            {
                var threadSeed = (uint)(seed*(threadId + 1)*(threadId + 1));
                Console.WriteLine("The seed for thread {0} is: {1}", threadId+1, threadSeed);
                return new LevelMaker(threadSeed).MakeLevels(levelSettings).Take(levelsPerThread);
            });

            var bestLevel = levels.OrderByDescending(x => x.NumberOfRooms).First();

            Console.WriteLine(bestLevel);
            Console.WriteLine((int)Math.Round(sw.Elapsed.TotalMilliseconds));
        }
예제 #4
0
        public IEnumerable<Level> MakeLevels(LevelSettings settings)
        {
            while(true)
            {
                var lev = new Level(settings.MaxRooms, settings.TileDim);

                int roomCount = 0;
                for (int attempt = 0; attempt < settings.RoomInsertionAttempts; attempt++)
                {
                    var x = _rand.Next() % settings.TileDim;
                    var y = _rand.Next() % settings.TileDim;
                    var w = _rand.Next() % settings.RestWidMax + settings.WidMin;
                    var h = _rand.Next() % settings.RestWidMax + settings.WidMin;

                    if (x + w >= settings.TileDim || y + h >= settings.TileDim || x == 0 || y == 0) continue;
                    var room = new Room{X=x, Y=y, W=w, H=h};
                    if (lev.TryAddRoom(room))
                    {
                        if (++roomCount == settings.MaxRooms)
                            break;
                    }
                }

                yield return lev;
            }
        }