Beispiel #1
0
    protected override void Awake()
    {
        if (Instance != null)
        {
            photonView.enabled = false;
            gameObject.SetActive(false);
            Destroy(this.gameObject);
            return;
        }

        base.Awake();
        Instance = this;
        MapGeneratorV2 mg = FindObjectOfType <MapGeneratorV2>();

        if (mg.IsTesting)
        {
            m_RandomNumberGenerator = new MT19937(mg.Seed);
            UnityEngine.Random.InitState((int)mg.Seed);
        }
        else
        {
            m_RandomNumberGenerator = new MT19937((ulong)GameManager.Instance.SeedValue);
            UnityEngine.Random.InitState(GameManager.Instance.SeedValue);
        }

        m_ItemsInGame       = new Dictionary <string, AbstractItem>();
        m_PickUpItemsInGame = new Dictionary <string, AbstractItem>();

        GameManager.Instance.DontDestroyNormalObject(gameObject);
        GameManager.PostPlayer += InitializeItemManager;
    }
Beispiel #2
0
        public void CompareSequencesOfMersennes()
        {
            Random rnd = new Random();

            for (int i = 0; i < 10; i++)
            {
                int seed = rnd.Next();
                var m1   = new MT19937();
                m1.init_genrand((ulong)seed);
                var m2 = new RandomMT((ulong)seed);
                var m3 = new SharpDevs.Randomization.MersenneTwister(seed);
                var m4 = new Random(seed);

                for (int j = 0; j < 10; j++)
                {
                    var r1 = m1.genrand_int32();
                    var r2 = m2.RandomInt();
                    var r3 = m3.GetNextULong();
                    var r4 = m4.Next();

                    Console.WriteLine("{0}\t{1}\t{2}\t{3}", r1, r2, r3, r4);

                    //Assert.AreEqual(r1, r2);
                    //Assert.AreEqual(r2, r3);
                }

                Console.WriteLine();
            }
        }
Beispiel #3
0
    public static void Main(string[] args)
    {
        var mt = new MT19937();

        mt.Seed(new ulong[] { 0x12345UL, 0x23456UL, 0x34567UL, 0x45678UL });

        var i = 0;

        foreach (ulong want in expectedInt)
        {
            var have = mt.UInt64();
            if (have != want)
            {
                Console.WriteLine("wrong output {0}: {1} != {2}", i, have, want);
                return;
            }
            i++;
        }

        i = 0;
        foreach (string want in expectedReal)
        {
            var have = mt.Real2().ToString("0.00000000");
            if (have != want)
            {
                Console.WriteLine("wrong output {0}: {1} != {2}", i, have, want);
                return;
            }
            i++;
        }

        Console.WriteLine("done");
    }
Beispiel #4
0
        public void Challenge21_Implement_the_MT19937_Mersenne_Twister_RNG()
        {
            var rng = new MT19937();

            rng.SeedMt(5489);

            var list1 = new List <uint>(1000);

            for (int i = 0; i < 1000; ++i)
            {
                list1.Add(rng.ExtractNumber());
            }

            var rng2 = new MT19937();

            rng2.SeedMt(5489);

            var list2 = new List <uint>(1000);

            for (int i = 0; i < 1000; ++i)
            {
                list2.Add(rng2.ExtractNumber());
            }

            Assert.Equal(list1, list2);
            Assert.Equal(list1.Take(10), new uint[] { 0xD091BB5C, 0x22AE9EF6, 0xE7E1FAEE, 0xD5C31F79, 0x2082352C, 0xF807B7DF, 0xE9D30005, 0x3895AFE1, 0xA1E24BBA, 0x4EE4092B });
        }
Beispiel #5
0
        public static void StartChitokuChin()
        {
            mt = new MT19937((uint)(DateTime.Now.ToFileTimeUtc() % uint.MaxValue));

            var chitoq = new Queue <char>();

            foreach (var c in GetRandomString(5))
            {
                chitoq.Enqueue(c);
            }
            int count = 1;

            while (true)
            {
                if (chitoq.SequenceEqual("ちとくちん"))
                {
                    foreach (var c in chitoq)
                    {
                        Console.Write(c);
                    }

                    Console.WriteLine("\r\n\r\n\r\nちとくちんち~~~~ん!!!{0}回目でちとくちん", count + 4);
                    break;
                }
                count++;
                Console.Write(chitoq.Dequeue());
                chitoq.Enqueue(GetRandomString(1)[0]);
            }
        }
Beispiel #6
0
        public void Challenge23_Clone_an_MT19937_RNG_from_its_output()
        {
            var rng = new MT19937();

            rng.SeedMt(5489);

            // run random number of ExtractNumber
            // the cloning doesn't depend on internal index state
            using (var crnd = RandomNumberGenerator.Create())
            {
                var runCount = CryptoRandom.GetInt(crnd, 1, 2000);
                for (int i = 0; i < runCount; ++i)
                {
                    rng.ExtractNumber();
                }
            }

            var states = new List <uint>(624);

            for (int i = 0; i < states.Capacity; ++i)
            {
                states.Add(rng.ExtractNumber());
            }

            var clone = MT19937Cloner.Clone(states);

            for (int i = 0; i < 1000; ++i)
            {
                Assert.Equal(rng.ExtractNumber(), clone.ExtractNumber());
            }
        }
Beispiel #7
0
        public void Next()
        {
            Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var rnd = new MT19937(852456);

            var actual = new int[100];

            for (var i = 0; i < 100; ++i)
            {
                actual[i] = rnd.Next();
                Console.Write("{0}, ", actual[i]);
                if (i % 10 == 9)
                {
                    Console.WriteLine();
                }
            }

            Assert.Equal(new int[]
            {
                -1016690674, -1637870728, -692783469, -323248999, -1533665771, -1800427152, 1662001996, 2084386684, -757433287, 120032001,
                -1705096166, -1591729151, 1623952413, -785304155, 1108132845, 834940583, -1061792856, 1292875383, 1530193206, -958834311,
                -521422406, -1476584847, 1644928184, 1260721938, -759842211, -299687162, -1378585833, 439242734, -1387971947, -1811371473,
                -1985714671, -1068376625, -483596985, -1378429075, -2094662442, -1881951118, -2078293020, -1151429745, 2018416447, 1893879858,
                1326341598, -87012482, 327821473, -1207695435, 235559859, 2134760270, -1323840169, 1267399315, 531294005, -786136418,
                -453675209, 150317649, -1794148827, -1948085738, -1255531484, -1764054824, 767062180, 401275128, -1732525675, 1339059654,
                52391037, 1805419262, 1510642622, -1869031373, 1921352644, 1081859104, -1066381150, -1383572376, -251843853, 202259689,
                -1714270235, -1892268470, -1011817250, 1412463953, 220111516, -1565265572, 576040432, -420655050, -196418315, -193552307,
                -196005994, 2095968849, -1782680971, -1027966515, -468055061, -377912262, 439807374, 691554137, 520414605, 2002406186,
                719115332, 986992980, 620206509, 123073363, 1440013716, 557741451, -1815315156, -1496982324, -427519681, 380279830,
            }, actual);

            rnd.Init(456321);

            for (var i = 0; i < 100; ++i)
            {
                actual[i] = rnd.Next();
                Console.Write("{0}, ", actual[i]);
                if (i % 10 == 9)
                {
                    Console.WriteLine();
                }
            }

            Assert.Equal(new int[]
            {
                1823309890, 1286026978, 1700772777, -759084818, -1939449827, -1969269924, -1324637702, 1237751839, 1579467185, -1896356529,
                -1662531782, -1290070889, -1340729546, -462290590, 1893630519, 883728674, 817296192, -355085204, 1134931239, 1948959821,
                -564395120, -2099114907, 42843971, 478456745, 1761551733, -1914916423, 1044512791, 1455306705, -946573955, -728202319,
                1294804702, -1632067386, -186955106, 1032025171, -1373329726, 1691086447, 864646121, 1575177187, -1100242554, -874273313,
                1445571059, -1557846233, 626484120, -237187437, -888254806, -1897784757, -898232603, -78541345, -1069259125, -1336913358,
                -647024102, -940540444, 1392542934, -714307271, 523185203, -1169442940, -314834783, -124191978, 928627036, 180896026,
                -882290420, 28937894, -847412374, -597367692, 1166787309, 2034421376, 1224967835, 157701398, 1421075282, -2007011874,
                2009755335, 257512274, -111371144, 1646144901, 1911530226, -1144353162, 149005087, 917397968, -157892715, 917308110,
                -835347687, -1916905346, 2068358733, -83070125, 1597863186, -1886652522, 126063062, -1220114000, 81072986, 126356288,
                876814749, -745490213, 1334729031, 323609085, -1118853331, -1672600046, 89372839, -1890792525, 255461946, -195118879,
            }, actual);
        }
Beispiel #8
0
        public virtual int sceMt19937Init(TPointer mt19937Addr, int seed)
        {
            SceMT19937 mt19937 = new SceMT19937();

            MT19937.init(mt19937, seed);
            mt19937.write(mt19937Addr);

            return(0);
        }
Beispiel #9
0
 public static void Main(string[] args)
 {
     using (MT19937 prng = new MT19937()) {
         for (var i = 0; i < 20; i++)
         {
             var f = prng.get_real(30.0f);
             Console.WriteLine($"{Align(i.ToString(), 3)} {Align(Hashes(f),30)}  rs =  {Align(f.ToString(), 10)} / {prng.get_uint32()}");
         }
     }
 }
Beispiel #10
0
        public virtual int sceMt19937UInt(SceMT19937 mt19937)
        {
            int random = MT19937.getInt(mt19937);

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("sceMt19937UInt returning 0x{0:X8}", random));
            }
            mt19937.write(Memory.Instance);

            return(random);
        }
Beispiel #11
0
        public void NextDouble()
        {
            Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var rnd = new MT19937(123456);

            var actual = new double[100];

            for (var i = 0; i < 100; ++i)
            {
                actual[i] = Math.Round(rnd.NextDouble(), 6);
            }

            Assert.Equal(new double[]
            {
                0.898029, 0.654526, 0.304360, 0.724096, 0.692163, 0.762186, 0.017384, 0.863317, 0.440578, 0.327692,
                0.157624, 0.194010, 0.487429, 0.230038, 0.440785, 0.810590, 0.563060, 0.092952, 0.530282, 0.854167,
                0.228575, 0.763807, 0.606799, 0.026897, 0.658474, 0.866361, 0.106265, 0.446750, 0.367851, 0.505000,
                0.869097, 0.519178, 0.874243, 0.163699, 0.186622, 0.550845, 0.189079, 0.020268, 0.916089, 0.573960,
                0.414645, 0.906261, 0.182299, 0.434931, 0.633394, 0.905933, 0.324769, 0.126503, 0.917170, 0.493531,
                0.426479, 0.942722, 0.269054, 0.948500, 0.972566, 0.371763, 0.840350, 0.962808, 0.052126, 0.302453,
                0.736815, 0.691647, 0.519616, 0.720329, 0.804298, 0.270261, 0.979788, 0.118823, 0.864857, 0.918150,
                0.335647, 0.970717, 0.268570, 0.182163, 0.296486, 0.638157, 0.901131, 0.651100, 0.886426, 0.379444,
                0.853851, 0.601951, 0.085475, 0.255315, 0.017430, 0.312999, 0.032936, 0.095106, 0.816612, 0.373813,
                0.143905, 0.007874, 0.419690, 0.280102, 0.348921, 0.098547, 0.719365, 0.117563, 0.938149, 0.935187,
            }, actual);

            rnd.Init(951753);

            for (var i = 0; i < 100; ++i)
            {
                actual[i] = Math.Round(rnd.NextDouble(), 6);
            }

            Assert.Equal(new double[]
            {
                0.164258, 0.362222, 0.476577, 0.368516, 0.270835, 0.938640, 0.482388, 0.033788, 0.581499, 0.483967,
                0.112844, 0.315118, 0.693525, 0.593817, 0.122376, 0.352409, 0.139571, 0.435325, 0.156437, 0.434273,
                0.309665, 0.963321, 0.210233, 0.695153, 0.893191, 0.226208, 0.888139, 0.983691, 0.347230, 0.628064,
                0.825325, 0.904256, 0.953110, 0.734535, 0.170423, 0.334555, 0.841246, 0.730140, 0.788088, 0.000813,
                0.502416, 0.320501, 0.187989, 0.802559, 0.326378, 0.886604, 0.421912, 0.258907, 0.771110, 0.266313,
                0.188474, 0.865032, 0.830199, 0.735948, 0.045387, 0.608558, 0.266344, 0.878086, 0.296003, 0.954960,
                0.840953, 0.834262, 0.784732, 0.560700, 0.337408, 0.438021, 0.205282, 0.390405, 0.395393, 0.895767,
                0.176438, 0.163167, 0.182486, 0.870010, 0.591199, 0.131195, 0.742142, 0.799884, 0.432466, 0.359904,
                0.641052, 0.527554, 0.406604, 0.792959, 0.908348, 0.594474, 0.939199, 0.123638, 0.804795, 0.720115,
                0.345518, 0.909825, 0.518950, 0.429536, 0.059868, 0.943975, 0.283047, 0.918471, 0.280611, 0.982255,
            }, actual);
        }
Beispiel #12
0
    void generate(uint seed)
    {
        MT19937 generator = new MT19937(seed);

        var elevation = generateElevation(generator);
        var tiles     = generateBiomes(elevation, generator);

        draw(tiles, generator);

        LevelMap.instance.tiles = tiles;

        placeImportantPoints(generator);
        placeBordeaux(generator);
        placeSpawnPoint();
        createMinimap();
    }
Beispiel #13
0
    private static List <GameObject> m_UsedBossRooms;      //A static list of all the used boss rooms
    #endregion

    #region Unity Methods
    private void Awake()
    {
        //error checking for exposed values
        if (BossRoomPrefab.Count < 1)
        {
            Debug.LogError("No boss rooms are attached to the BossRoomPrefab list in the MapGeneratorV2, fix this.", this);
        }
        if (UniqueRooms.Count < 1)
        {
            Debug.LogError("No unique rooms are attached to the UniqueRooms list in the MapGeneratorV2, fix this.", this);
        }
        if (RoomPrefabs.Count < 1)
        {
            Debug.LogError("No rooms are attached to the RoomPrefabs list in the MapGeneratorV2, fix this.", this);
        }
        if (SpawnRoom == null)
        {
            Debug.LogError("No spawn room is attached to the SpawnRoom list in the MapGeneratorV2, fix this.", this);
        }

        //initliaze values
        m_RoomsToBuildFrom = new List <GameObject>();
        m_BuiltUniqueRooms = new List <int>();
        m_GizmoPositions   = new List <Vector3>();
        m_GizmoSizes       = new List <Vector3>();
        m_LayerMask        = LayerMask.GetMask("MapGeometry");

        //intialize the random number generator
        if (!IsTesting)
        {
            m_Seed = (ulong)GameManager.Instance.SeedValue;
        }
        m_RandomNumberGenerator = new MT19937(m_Seed);

        if (m_UsedBossRooms == null)
        {
            m_UsedBossRooms = new List <GameObject>();
        }

        CreateNewBossRoom();

        RoomLimit += GameManager.FloorNumber * 2;

        GameManager.LevelGeneration += GenerateLevel;
        SceneManager.sceneUnloaded  += OnSceneUnloaded;
    }
Beispiel #14
0
        public void Challenge22_Crack_an_MT19937_seed()
        {
            int  unixTimestamp;
            uint seed;
            uint currentRandomNumber;

            using (var crnd = RandomNumberGenerator.Create())
            {
                unixTimestamp  = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                unixTimestamp += CryptoRandom.GetInt(crnd, 40, 1000);

                var rng = new MT19937();
                seed = (uint)unixTimestamp;
                rng.SeedMt(seed);

                unixTimestamp      += CryptoRandom.GetInt(crnd, 40, 1000);
                currentRandomNumber = rng.ExtractNumber();
            }

            // check every possible second from the last twenty-four hours
            uint foundSeed = 0;

            for (int i = unixTimestamp; i > (unixTimestamp - 86400); --i)
            {
                var rng = new MT19937();
                rng.SeedMt((uint)i);

                if (rng.ExtractNumber() == currentRandomNumber)
                {
                    foundSeed = (uint)i;
                    break;
                }
            }

            Assert.Equal(seed, foundSeed);
        }
Beispiel #15
0
        public void CompareDistributionOfMersennes()
        {
            Random rnd      = new Random();
            int    baseSeed = rnd.Next();

            var m1 = new MT19937();

            m1.init_genrand((ulong)baseSeed);
            var m2         = new RandomMT((ulong)baseSeed);
            var m3         = new SharpDevs.Randomization.MersenneTwister(baseSeed);
            var m4         = new Random(baseSeed);
            var maxRange   = 1000;
            var iterations = 10000000;

            var dist1 = this.CalculateDistribution(() => m1.RandomRange(0, maxRange - 1), maxRange, iterations);
            var dist2 = this.CalculateDistribution(() => m2.RandomRange(0, maxRange - 1), maxRange, iterations);
            var dist3 = this.CalculateDistribution(() => m3.GetNext(0, maxRange), maxRange, iterations);
            var dist4 = this.CalculateDistribution(() => m4.Next(0, maxRange), maxRange, iterations);

            var distribution1 = this.AnalyzeDistribution(dist1, iterations);
            var distribution2 = this.AnalyzeDistribution(dist2, iterations);
            var distribution3 = this.AnalyzeDistribution(dist3, iterations);
            var distribution4 = this.AnalyzeDistribution(dist4, iterations);

            Console.WriteLine("{0}\t{1}\t{2}\t{3}",
                              distribution1, distribution2, distribution3, distribution4);
            var expectedFill = (decimal)iterations / maxRange;

            Console.WriteLine("Przy oczekiwanym napełnieniu: " + expectedFill);
            Console.WriteLine("Co daje procentowo:");
            Console.WriteLine("{0}\t{1}\t{2}\t{3}",
                              distribution1 / expectedFill * 100,
                              distribution2 / expectedFill * 100,
                              distribution3 / expectedFill * 100,
                              distribution4 / expectedFill * 100);
        }
 //creates a new instance of a tcp port listener for a given site
 public PortListener(Site site,sIPPortPair ipp)
 {
     _rand = new MT19937(DateTime.Now.Ticks);
     _sites = new List<Site>();
     _sites.Add(site);
     _port = ipp.Port;
     _ip = ipp.Address;
     _useSSL = ipp.UseSSL;
     _idleSeonds = (long)Math.Min(_idleSeonds, ipp.IdleSeconds);
     _totalRunSeconds = (long)Math.Min(_totalRunSeconds, ipp.TotalRunSeconds);
     _backLog = (int)Math.Min(_backLog, ipp.BackLog);
 }
Beispiel #17
0
 public EventController()
 {
     _mut      = new Mutex(false);
     _rand     = new MT19937(DateTime.Now.Ticks);
     _handlers = new List <sEventHandler>();
 }
Beispiel #18
0
 static EventController()
 {
     _rand     = new MT19937(DateTime.Now.Ticks);
     _handlers = new List <IEventHandler>();
 }
 internal void Start(Socket s, PortListener listener, X509Certificate cert,long id)
 {
     _idleTimer = new Timer(new TimerCallback(_IdleTimeout), null, _CONNECTION_IDLE_TIMEOUT, Timeout.Infinite);
     _rand = new MT19937(id);
     _buffer = new byte[_BUFFER_SIZE];
     _requests = new List<HttpRequest>();
     _parser.RequestLineRecieved = _RequestLineRecieved;
     _shutdown = false;
     _id = id;
     socket = s;
     _listener = listener;
     _cert = cert;
     _currentConnection = this;
     if (_listener.UseSSL)
     {
         _inputStream = new WrappedStream(new SslStream(new NetworkStream(socket), true));
         _inputStream.AuthenticateAsServer(_cert);
     }
     else
         _inputStream = new WrappedStream(new NetworkStream(socket));
     _inputStream.BeginRead(_buffer, 0, _buffer.Length, new AsyncCallback(OnReceive), null);
 }
 public sCommand(string command, bool api, MT19937 random)
 {
     _id      = random.NextLong();
     _api     = api;
     _command = command;
 }
Beispiel #21
0
 public Site() {
     _rand = new MT19937(DateTime.Now.Ticks);
 }
Beispiel #22
0
    public Map(ushort width, ushort height, int numberOfPlayers, ulong _Seed, bool force = false) : this(width, height)
    {
        //Pseudorandom number generator.
        this.prg = new MT19937();
        this.prg.init_genrand(_Seed);

        //Decides whether to put more players along the horizontal or the vertical.
        var preferHorizontal = this.prg.genrand_int31() % 2 == 1;

        int dw, dh;

        //Find number closest to square that makes the match symmetric.
        if (preferHorizontal)
        {
            dh = (int)Math.Sqrt(numberOfPlayers);
            while (numberOfPlayers % dh != 0)
            {
                dh--;
            }
            dw = numberOfPlayers / dh;
        }
        else
        {
            dw = (int)Math.Sqrt(numberOfPlayers);
            while (numberOfPlayers % dw != 0)
            {
                dw--;
            }
            dh = numberOfPlayers / dw;
        }

        //Figure out chunk width and height accordingly.
        //Matches width and height as closely as it can, but is not guaranteed to match exactly.
        //It is guaranteed to be smaller if not the same size, however.
        var cw = width / dw;
        var ch = height / dh;

        //Ensure that we'll be able to move the tesselation by a uniform amount.
        if (preferHorizontal)
        {
            while (ch % numberOfPlayers != 0)
            {
                ch--;
            }
        }
        else
        {
            while (cw % numberOfPlayers != 0)
            {
                cw--;
            }
        }

        this.map_width  = cw * dw;
        this.map_height = ch * dh;


        var prodRegion = new Region(cw, ch, () => this.prg.genrand_real1());
        List <List <double> > prodChunk = prodRegion.GetFactors();

        var strengthRegion = new Region(cw, ch, () => this.prg.genrand_real1());
        List <List <double> > strengthChunk = strengthRegion.GetFactors();


        //We'll first tesselate the map; we'll apply our various translations and transformations later.
        var tesselation = new SiteD[this.map_height, this.map_width];

        for (var a = 0; a < dh; a++)
        {
            for (var b = 0; b < dw; b++)
            {
                for (var c = 0; c < ch; c++)
                {
                    for (var d = 0; d < cw; d++)
                    {
                        tesselation[a * ch + c, b *cw + d].production = prodChunk[c][d];
                        tesselation[a * ch + c, b *cw + d].strength   = strengthChunk[c][d];
                    }
                }
                tesselation[a * ch + ch / 2, b *cw + cw / 2].owner = (char)(a * dw + b + 1);  //Set owners.
            }
        }


        //We'll now apply the reflections to the map.
        bool reflectVertical = dh % 2 == 0, reflectHorizontal = dw % 2 == 0; //Am I going to reflect in the horizontal vertical directions at all?
        var  reflections = new SiteD[this.map_height, this.map_width];

        for (var a = 0; a < dh; a++)
        {
            for (var b = 0; b < dw; b++)
            {
                bool vRef = reflectVertical && a % 2 != 0, hRef = reflectHorizontal && b % 2 != 0; //Do I reflect this chunk at all?
                for (var c = 0; c < ch; c++)
                {
                    for (var d = 0; d < cw; d++)
                    {
                        reflections[a * ch + c, b *cw + d] = tesselation[a * ch + (vRef ? ch - c - 1 : c), b *cw + (hRef ? cw - d - 1 : d)];
                    }
                }
            }
        }

        //Next, let's apply our shifts to create the shifts map.
        var shifts = new SiteD[this.map_height, this.map_height];

        if (preferHorizontal)
        {
            var shift = (this.prg.genrand_int31() % dw == 1 ? 1 : 0) * (this.map_height / dw); //A vertical shift.
            for (var a = 0; a < dh; a++)
            {
                for (var b = 0; b < dw; b++)
                {
                    for (var c = 0; c < ch; c++)
                    {
                        for (var d = 0; d < cw; d++)
                        {
                            shifts[a * ch + c, b *cw + d] = reflections[(a * ch + b * shift + c) % this.map_height, b *cw + d];
                        }
                    }
                }
            }
        }
        else
        {
            var shift = (this.prg.genrand_int31() % dh == 1 ? 1 : 0) * (this.map_width / dh); //A horizontal shift.
            for (var a = 0; a < dh; a++)
            {
                for (var b = 0; b < dw; b++)
                {
                    for (var c = 0; c < ch; c++)
                    {
                        for (var d = 0; d < cw; d++)
                        {
                            shifts[a * ch + c, b *cw + d] = reflections[a * ch + c, (b * cw + a * shift + d) % this.map_width];
                        }
                    }
                }
            }
        }

        //Apply a final blur to create the blur map. This will fix the edges where our transformations have created jumps or gaps.
        const double OWN_WEIGHT = 0.66667;
        var          blur       = new SiteD[this.map_height, this.map_width];

        Array.Copy(shifts, blur, this.map_height * this.map_width);

        for (var z = 0; z <= 2 * Math.Sqrt(this.map_width * this.map_height) / 10; z++)
        {
            var newBlur = new SiteD[this.map_height, this.map_width];
            Array.Copy(blur, newBlur, this.map_height * this.map_width);

            for (var a = 0; a < this.map_height; a++)
            {
                int mh = a - 1, ph = a + 1;
                if (mh < 0)
                {
                    mh += this.map_height;
                }
                if (ph == this.map_height)
                {
                    ph = 0;
                }
                for (var b = 0; b < this.map_width; b++)
                {
                    int mw = b - 1, pw = b + 1;
                    if (mw < 0)
                    {
                        mw += this.map_width;
                    }
                    if (pw == this.map_width)
                    {
                        pw = 0;
                    }

                    newBlur[a, b].production *= OWN_WEIGHT;
                    newBlur[a, b].production += blur[mh, b].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].production += blur[ph, b].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].production += blur[a, mw].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].production += blur[a, pw].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   *= OWN_WEIGHT;
                    newBlur[a, b].strength   += blur[mh, b].strength * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   += blur[ph, b].strength * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   += blur[a, mw].strength * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   += blur[a, pw].strength * (1 - OWN_WEIGHT) / 4;
                }
            }
            blur = newBlur;
        }

        //Let's now normalize the map values.
        double maxProduction = 0, maxStrength = 0;
        var    normalized = new SiteD[this.map_height, this.map_width];

        Array.Copy(blur, normalized, this.map_height * this.map_width);

        foreach (var b in normalized)
        {
            if (b.production > maxProduction)
            {
                maxProduction = b.production;
            }
            if (b.strength > maxStrength)
            {
                maxStrength = b.strength;
            }
        }

        for (var i = 0; i < this.map_height; i++)
        {
            for (var j = 0; j < this.map_width; j++)
            {
                normalized[i, j].production /= maxProduction;
                normalized[i, j].strength   /= maxStrength;
            }
        }

        //Finally, fill in the contents vector.
        var TOP_PROD = (int)(this.prg.genrand_int31() % 10 + 6);
        var TOP_STR  = (int)(this.prg.genrand_int31() % 106 + 150);

        this._sites = new Site[this.map_width, this.map_height];

        for (var a = 0; a < this.map_height; a++)
        {
            for (var b = 0; b < this.map_width; b++)
            {
                this._sites[b, a].Owner      = normalized[a, b].owner;
                this._sites[b, a].Strength   = (ushort)Math.Round(normalized[a, b].strength * TOP_STR);
                this._sites[b, a].Production = (ushort)Math.Round(normalized[a, b].production * TOP_PROD);
                if (this._sites[b, a].Owner != 0 && this._sites[b, a].Production == 0)
                {
                    this._sites[b, a].Production = 1;
                }
            }
        }
    }
 public EventController()
 {
     _mut = new Mutex(false);
     _rand = new MT19937(DateTime.Now.Ticks);
     _handlers = new List<sEventHandler>();
 }
 public sCommand(string command, bool api,MT19937 random)
 {
     _id = random.NextLong();
     _api = api;
     _command = command;
 }