Пример #1
0
        protected override void OnTorture()
        {
            while (!_abortSignal.IsCancellationRequested)
            {
                var count    = 0;
                var part     = Partitioner.Create(array);
                var syncRoot = new object();

                void TestIfPrime(int j)
                {
                    if (Magma.IsPrime(j))
                    {
                        lock (syncRoot) count++;
                    }
                }

                try
                {
                    Parallel.ForEach(part, new ParallelOptions
                    {
                        MaxDegreeOfParallelism = Environment.ProcessorCount,
                        CancellationToken      = _abortSignal.Token
                    }, TestIfPrime);
                }
                catch { }
            }
        }
Пример #2
0
 protected override void ItemAction(int item)
 {
     if (Magma.IsPrime(item))
     {
         lock (_syncLock) _c++;
     }
 }
Пример #3
0
 public void Magma()
 {
     Magma cipher = new Magma();
     cipher.SetKey(_ref_key);
     byte[] result = cipher.Encrypt(_ref_plain);
     CollectionAssert.AreEqual(_ref_cipher, result);
 }
Пример #4
0
 protected override void ItemAction(int item)
 {
     if (Magma.IsPrime(item))
     {
         _primes.Add(item);
     }
 }
Пример #5
0
 protected override void ItemAction(int j)
 {
     if (Magma.IsPrime(j))
     {
         _c++;
     }
 }
Пример #6
0
 public MCLQ(byte[] chunkBytes, MCNK parentChunk) : base(chunkBytes)
 {
     MinHeight = ReadSingle();
     MaxHeight = ReadSingle();
     for (int i = 0; i < 81; i++)
     {
         if (parentChunk.Flags.HasFlag(MCNKFlags.LiquidMagma))
         {
             Vertices[i] = new Magma();
         }
         else if (parentChunk.Flags.HasFlag(MCNKFlags.LiquidOcean))
         {
             Vertices[i] = new Ocean();
         }
         else
         {
             Vertices[i] = new Water();
         }
         Vertices[i].Read(this);
     }
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             Tiles[i, j] = ReadByte();
         }
     }
     NumberFlowvs = ReadUInt32();
     for (int i = 0; i < 3; i++)
     {
         Flowvs[i].Read(this);
     }
     Close();
 }
Пример #7
0
        private static void Main()
        {
            const int size = 100000;

            Console.WriteLine($"Inicializando arreglo de prueba con {size} elementos...");
            var c     = Magma.InitArray(size);
            var d     = 0;
            var tests = Magma.DiscoverObjects <MpTest>();

            foreach (var test in tests)
            {
                Console.WriteLine($"A continuación: {test.Name}{test.Description}");
                test.Run(c);
                Console.WriteLine($"{Environment.NewLine}Resultado: {test.Count}");
                Console.WriteLine(new string('-', 80));
                if (((ITest)test).IsDefault)
                {
                    d = test.Count;
                }
            }
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Resultados de las pruebas:");
            foreach (var j in tests)
            {
                Console.WriteLine($"{string.Concat((((ITest)j).IsDefault ? "(Referencia) " : null), j.Name),-50}{(j.Count == d ? "[OK]" : $"[FAIL ({d - j.Count})]")}");
            }
Пример #8
0
        public void Magma()
        {
            Magma cipher = new Magma();

            cipher.SetKey(_ref_key);
            byte[] result = cipher.Encrypt(_ref_plain);
            CollectionAssert.AreEqual(_ref_cipher, result);
        }
Пример #9
0
        public static void ToRelationTest()
        {
            var m = new Magma <int>((x, y) => x + y);
            var r = m.ToRelation();

            Assert.True(r.Contains((0, 0), 0));
            Assert.True(r.Contains((0, 0), 0));
            Assert.False(r.Contains((7, 3), 9));
        }
Пример #10
0
 public void AddFile(string fileName, string relativeFileName)
 {
     _list.Add(
         new FileListRow
     {
         Name     = relativeFileName,
         Length   = new FileInfo(fileName).Length,
         Checksum = Magma.CalculateFileChecksum(fileName)
     });
 }
Пример #11
0
 protected override void Benchmark(int[] array, Stopwatch t, ref int count)
 {
     t.Start();
     foreach (var j in array)
     {
         if (Magma.IsPrime(j))
         {
             count++;
         }
     }
     t.Stop();
 }
Пример #12
0
        public override void Run(int[] array)
        {
            var c = 0;

            foreach (var j in array)
            {
                if (Magma.IsPrime(j))
                {
                    c++;
                }
            }
            Count = c;
        }
Пример #13
0
 private void BuildMagmaMap(Point tileOrigin)
 {
     _sourceMagmaMap = new Magma[200, 200];
     _targetMagmaMap = new Magma[200, 200];
     for (int i = 0; i < _sourceMagmaMap.GetLength(0); i++)
     {
         for (int j = 0; j < _sourceMagmaMap.GetLength(1); j++)
         {
             int i2 = i + tileOrigin.X;
             int j2 = j + tileOrigin.Y;
             _sourceMagmaMap[i, j] = Magma.CreateEmpty(WorldGen.SolidTile(i2, j2) ? 4f : 1f);
             _targetMagmaMap[i, j] = _sourceMagmaMap[i, j];
         }
     }
 }
Пример #14
0
        private void PlaceGranite(Point tileOrigin, Rectangle magmaMapArea)
        {
            bool   flag = ShouldUseLava(tileOrigin);
            ushort type = 368;
            ushort wall = 180;

            if (WorldGen.drunkWorldGen)
            {
                type = 367;
                wall = 178;
            }
            for (int i = magmaMapArea.Left; i < magmaMapArea.Right; i++)
            {
                for (int j = magmaMapArea.Top; j < magmaMapArea.Bottom; j++)
                {
                    Magma magma = _sourceMagmaMap[i, j];
                    if (!magma.IsActive)
                    {
                        continue;
                    }
                    Tile  tile = GenBase._tiles[tileOrigin.X + i, tileOrigin.Y + j];
                    float num  = (float)Math.Sin((float)(tileOrigin.Y + j) * 0.4f) * 0.7f + 1.2f;
                    float num2 = 0.2f + 0.5f / (float)Math.Sqrt(Math.Max(0f, magma.Pressure - magma.Resistance));
                    if (Math.Max(1f - Math.Max(0f, num * num2), magma.Pressure / 15f) > 0.35f + (WorldGen.SolidTile(tileOrigin.X + i, tileOrigin.Y + j) ? 0f : 0.5f))
                    {
                        if (TileID.Sets.Ore[tile.type])
                        {
                            tile.ResetToType(tile.type);
                        }
                        else
                        {
                            tile.ResetToType(type);
                        }
                        tile.wall = wall;
                    }
                    else if (magma.Resistance < 0.01f)
                    {
                        WorldUtils.ClearTile(tileOrigin.X + i, tileOrigin.Y + j);
                        tile.wall = wall;
                    }
                    if (tile.liquid > 0 && flag)
                    {
                        tile.liquidType(1);
                    }
                }
            }
        }
Пример #15
0
        private static void Main()
        {
            const int size = 1000000;

            if (!Magma.SetMaxPriority())
            {
                Console.WriteLine($"No fue posible cambiar la prioridad de esta aplicación.");
            }

            Console.WriteLine($"Precompilando tests...");
            RunTests(Environment.ProcessorCount * 10, false);

            Console.WriteLine($"Inicializando arreglo de prueba con {size} elementos...");
            RunTests(size, true);

            var best = Tests.OrderBy(p => p.Time).First();

            Console.WriteLine($"Mejor tiempo: {best.Name}, {best.Time} ms");
        }
Пример #16
0
        private void PlaceDecorations(Point tileOrigin, Rectangle magmaMapArea)
        {
            FastRandom fastRandom = new FastRandom(Main.ActiveWorldFileData.Seed).WithModifier(65440uL);

            for (int i = magmaMapArea.Left; i < magmaMapArea.Right; i++)
            {
                for (int j = magmaMapArea.Top; j < magmaMapArea.Bottom; j++)
                {
                    Magma magma = _sourceMagmaMap[i, j];
                    int   num   = i + tileOrigin.X;
                    int   num2  = j + tileOrigin.Y;
                    if (!magma.IsActive)
                    {
                        continue;
                    }
                    WorldUtils.TileFrame(num, num2);
                    WorldGen.SquareWallFrame(num, num2);
                    FastRandom fastRandom2 = fastRandom.WithModifier(num, num2);
                    if (fastRandom2.Next(8) == 0 && GenBase._tiles[num, num2].active())
                    {
                        if (!GenBase._tiles[num, num2 + 1].active())
                        {
                            WorldGen.PlaceUncheckedStalactite(num, num2 + 1, fastRandom2.Next(2) == 0, fastRandom2.Next(3), spiders: false);
                        }
                        if (!GenBase._tiles[num, num2 - 1].active())
                        {
                            WorldGen.PlaceUncheckedStalactite(num, num2 - 1, fastRandom2.Next(2) == 0, fastRandom2.Next(3), spiders: false);
                        }
                    }
                    if (fastRandom2.Next(2) == 0)
                    {
                        Tile.SmoothSlope(num, num2);
                    }
                }
            }
        }
Пример #17
0
        private void SimulatePressure(out Rectangle effectedMapArea)
        {
            int length  = _sourceMagmaMap.GetLength(0);
            int length2 = _sourceMagmaMap.GetLength(1);
            int num     = length / 2;
            int num2    = length2 / 2;
            int num3    = num;
            int num4    = num3;
            int num5    = num2;
            int num6    = num5;

            for (int i = 0; i < 300; i++)
            {
                for (int j = num3; j <= num4; j++)
                {
                    for (int k = num5; k <= num6; k++)
                    {
                        Magma magma = _sourceMagmaMap[j, k];
                        if (!magma.IsActive)
                        {
                            continue;
                        }
                        float   num7 = 0f;
                        Vector2 zero = Vector2.Zero;
                        for (int l = -1; l <= 1; l++)
                        {
                            for (int m = -1; m <= 1; m++)
                            {
                                if (l == 0 && m == 0)
                                {
                                    continue;
                                }
                                Vector2 value  = _normalisedVectors[(l + 1) * 3 + (m + 1)];
                                Magma   magma2 = _sourceMagmaMap[j + l, k + m];
                                if (magma.Pressure > 0.01f && !magma2.IsActive)
                                {
                                    if (l == -1)
                                    {
                                        num3 = Utils.Clamp(j + l, 1, num3);
                                    }
                                    else
                                    {
                                        num4 = Utils.Clamp(j + l, num4, length - 2);
                                    }
                                    if (m == -1)
                                    {
                                        num5 = Utils.Clamp(k + m, 1, num5);
                                    }
                                    else
                                    {
                                        num6 = Utils.Clamp(k + m, num6, length2 - 2);
                                    }
                                    _targetMagmaMap[j + l, k + m] = magma2.ToFlow();
                                }
                                float pressure = magma2.Pressure;
                                num7 += pressure;
                                zero += pressure * value;
                            }
                        }
                        num7 /= 8f;
                        if (num7 > magma.Resistance)
                        {
                            float num8 = zero.Length() / 8f;
                            float val  = Math.Max(num7 - num8 - magma.Pressure, 0f) + num8 + magma.Pressure * 0.875f - magma.Resistance;
                            val = Math.Max(0f, val);
                            _targetMagmaMap[j, k] = Magma.CreateFlow(val, Math.Max(0f, magma.Resistance - val * 0.02f));
                        }
                    }
                }
                if (i < 2)
                {
                    _targetMagmaMap[num, num2] = Magma.CreateFlow(25f);
                }
                Utils.Swap(ref _sourceMagmaMap, ref _targetMagmaMap);
            }
            effectedMapArea = new Rectangle(num3, num5, num4 - num3 + 1, num6 - num5 + 1);
        }
Пример #18
0
        public override bool Place(Point origin, StructureMap structures)
        {
            if (GenBase._tiles[origin.X, origin.Y].active())
            {
                return(false);
            }
            int length  = _sourceMagmaMap.GetLength(0);
            int length2 = _sourceMagmaMap.GetLength(1);
            int num     = length / 2;
            int num2    = length2 / 2;

            origin.X -= num;
            origin.Y -= num2;
            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length2; j++)
                {
                    int i2 = i + origin.X;
                    int j2 = j + origin.Y;
                    _sourceMagmaMap[i, j] = Magma.CreateEmpty(WorldGen.SolidTile(i2, j2) ? 4f : 1f);
                    _targetMagmaMap[i, j] = _sourceMagmaMap[i, j];
                }
            }
            int num3 = num;
            int num4 = num;
            int num5 = num2;
            int num6 = num2;

            for (int k = 0; k < 300; k++)
            {
                for (int l = num3; l <= num4; l++)
                {
                    for (int m = num5; m <= num6; m++)
                    {
                        Magma magma = _sourceMagmaMap[l, m];
                        if (!magma.IsActive)
                        {
                            continue;
                        }
                        float   num7 = 0f;
                        Vector2 zero = Vector2.Zero;
                        for (int n = -1; n <= 1; n++)
                        {
                            for (int num8 = -1; num8 <= 1; num8++)
                            {
                                if (n == 0 && num8 == 0)
                                {
                                    continue;
                                }
                                Vector2 value = new Vector2(n, num8);
                                value.Normalize();
                                Magma magma2 = _sourceMagmaMap[l + n, m + num8];
                                if (magma.Pressure > 0.01f && !magma2.IsActive)
                                {
                                    if (n == -1)
                                    {
                                        num3 = Utils.Clamp(l + n, 1, num3);
                                    }
                                    else
                                    {
                                        num4 = Utils.Clamp(l + n, num4, length - 2);
                                    }
                                    if (num8 == -1)
                                    {
                                        num5 = Utils.Clamp(m + num8, 1, num5);
                                    }
                                    else
                                    {
                                        num6 = Utils.Clamp(m + num8, num6, length2 - 2);
                                    }
                                    _targetMagmaMap[l + n, m + num8] = magma2.ToFlow();
                                }
                                float pressure = magma2.Pressure;
                                num7 += pressure;
                                zero += pressure * value;
                            }
                        }
                        num7 /= 8f;
                        if (num7 > magma.Resistance)
                        {
                            float num9 = zero.Length() / 8f;
                            float val  = Math.Max(num7 - num9 - magma.Pressure, 0f) + num9 + magma.Pressure * 0.875f - magma.Resistance;
                            val = Math.Max(0f, val);
                            _targetMagmaMap[l, m] = Magma.CreateFlow(val, Math.Max(0f, magma.Resistance - val * 0.02f));
                        }
                    }
                }
                if (k < 2)
                {
                    _targetMagmaMap[num, num2] = Magma.CreateFlow(25f);
                }
                Utils.Swap(ref _sourceMagmaMap, ref _targetMagmaMap);
            }
            bool flag  = origin.Y + num2 > WorldGen.lavaLine - 30;
            bool flag2 = false;

            for (int num10 = -50; num10 < 50; num10++)
            {
                if (flag2)
                {
                    break;
                }
                for (int num11 = -50; num11 < 50; num11++)
                {
                    if (flag2)
                    {
                        break;
                    }
                    if (GenBase._tiles[origin.X + num + num10, origin.Y + num2 + num11].active())
                    {
                        switch (GenBase._tiles[origin.X + num + num10, origin.Y + num2 + num11].type)
                        {
                        case 147:
                        case 161:
                        case 162:
                        case 163:
                        case 200:
                            flag  = false;
                            flag2 = true;
                            break;
                        }
                    }
                }
            }
            for (int num12 = num3; num12 <= num4; num12++)
            {
                for (int num13 = num5; num13 <= num6; num13++)
                {
                    Magma magma3 = _sourceMagmaMap[num12, num13];
                    if (!magma3.IsActive)
                    {
                        continue;
                    }
                    Tile  tile  = GenBase._tiles[origin.X + num12, origin.Y + num13];
                    float num14 = (float)Math.Sin((float)(origin.Y + num13) * 0.4f) * 0.7f + 1.2f;
                    float num15 = 0.2f + 0.5f / (float)Math.Sqrt(Math.Max(0f, magma3.Pressure - magma3.Resistance));
                    float val2  = 1f - Math.Max(0f, num14 * num15);
                    val2 = Math.Max(val2, magma3.Pressure / 15f);
                    if (val2 > 0.35f + (WorldGen.SolidTile(origin.X + num12, origin.Y + num13) ? 0f : 0.5f))
                    {
                        if (TileID.Sets.Ore[tile.type])
                        {
                            tile.ResetToType(tile.type);
                        }
                        else
                        {
                            tile.ResetToType(368);
                        }
                        tile.wall = 180;
                    }
                    else if (magma3.Resistance < 0.01f)
                    {
                        WorldUtils.ClearTile(origin.X + num12, origin.Y + num13);
                        tile.wall = 180;
                    }
                    if (tile.liquid > 0 && flag)
                    {
                        tile.liquidType(1);
                    }
                }
            }
            List <Point16> list = new List <Point16>();

            for (int num16 = num3; num16 <= num4; num16++)
            {
                for (int num17 = num5; num17 <= num6; num17++)
                {
                    Magma magma4 = _sourceMagmaMap[num16, num17];
                    if (!magma4.IsActive)
                    {
                        continue;
                    }
                    int num18 = 0;
                    int num19 = num16 + origin.X;
                    int num20 = num17 + origin.Y;
                    if (!WorldGen.SolidTile(num19, num20))
                    {
                        continue;
                    }
                    for (int num21 = -1; num21 <= 1; num21++)
                    {
                        for (int num22 = -1; num22 <= 1; num22++)
                        {
                            if (WorldGen.SolidTile(num19 + num21, num20 + num22))
                            {
                                num18++;
                            }
                        }
                    }
                    if (num18 < 3)
                    {
                        list.Add(new Point16(num19, num20));
                    }
                }
            }
            foreach (Point16 item in list)
            {
                int x = item.X;
                int y = item.Y;
                WorldUtils.ClearTile(x, y, frameNeighbors: true);
                GenBase._tiles[x, y].wall = 180;
            }
            list.Clear();
            for (int num23 = num3; num23 <= num4; num23++)
            {
                for (int num24 = num5; num24 <= num6; num24++)
                {
                    Magma magma5 = _sourceMagmaMap[num23, num24];
                    int   num25  = num23 + origin.X;
                    int   num26  = num24 + origin.Y;
                    if (!magma5.IsActive)
                    {
                        continue;
                    }
                    WorldUtils.TileFrame(num25, num26);
                    WorldGen.SquareWallFrame(num25, num26);
                    if (GenBase._random.Next(8) == 0 && GenBase._tiles[num25, num26].active())
                    {
                        if (!GenBase._tiles[num25, num26 + 1].active())
                        {
                            WorldGen.PlaceTight(num25, num26 + 1, 165);
                        }
                        if (!GenBase._tiles[num25, num26 - 1].active())
                        {
                            WorldGen.PlaceTight(num25, num26 - 1, 165);
                        }
                    }
                    if (GenBase._random.Next(2) == 0)
                    {
                        Tile.SmoothSlope(num25, num26);
                    }
                }
            }
            return(true);
        }
Пример #19
0
        /// <summary>
        /// Шифратор
        /// </summary>
        /// <param name="data"></param>
        /// <param name="key"></param>
        /// <param name="cipher"></param>
        /// <returns></returns>
        private static byte[] Encrypt(string data, byte[] key, string cipher)
        {
            byte[] result;
            int    sizeBlock;

            switch (cipher)
            {
            case "Нет":
                result = Encoding.GetEncoding(866).GetBytes(data);
                break;

            case "Кузнечик":
                Kuznyechik kuznyechik = new Kuznyechik();
                sizeBlock = 16;

                //Если количество блоков не пропорционально размеру блока, то дописываем символы заполнения
                while (data.Length % sizeBlock != 0)
                {
                    data += "┼";
                }

                //Кодируем текст в массив байт
                byte[] dataBytes = Encoding.GetEncoding(866).GetBytes(data);
                result = new byte[dataBytes.Length];

                //В цикле формируем блоки...
                for (int i = 0; i < dataBytes.Length; i += sizeBlock)
                {
                    byte[] data8bytes = new byte[sizeBlock];

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        data8bytes[k] = dataBytes[k + i];
                    }

                    //...и зашфровывем эти блоки с помощью ключа
                    byte[] dataE8bytes = kuznyechik.encrypt(data8bytes, key);

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        result[k + i] = dataE8bytes[k];
                    }
                }
                break;

            case "Магма":
                //Аналогично Кузнечику
                Magma magma = new Magma();
                sizeBlock = 8;

                while (data.Length % sizeBlock != 0)
                {
                    data += "┼";
                }

                dataBytes = Encoding.GetEncoding(866).GetBytes(data);
                result    = magma.Encode(dataBytes, key);
                break;

            case "AES":
                //Аналогично Кузнечику
                sizeBlock = 16;

                Aes aes = Aes.Create();
                aes.Mode      = CipherMode.ECB;
                aes.KeySize   = 256;
                aes.BlockSize = sizeBlock * 8;
                aes.Key       = key;
                aes.Padding   = PaddingMode.Zeros;

                ICryptoTransform encryptor = aes.CreateEncryptor();

                while (data.Length % sizeBlock != 0)
                {
                    data += "┼";
                }

                dataBytes = Encoding.GetEncoding(866).GetBytes(data);
                result    = encryptor.TransformFinalBlock(dataBytes, 0, dataBytes.Length);
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }
Пример #20
0
        /// <summary>
        /// Дешифратор
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string Decrypt(Packet packet, byte[] key)
        {
            string result = "";
            int    sizeBlock;

            //В зависимости от шифра, выполняются разные действия
            switch (packet.cipher)
            {
            case "Нет":
            case null:
                //Если шифра нет, то просто декодируем байты в текст
                result = Encoding.GetEncoding(866).GetString(packet.data);
                break;

            case "Кузнечик":
                Kuznyechik kuznyechik = new Kuznyechik();
                sizeBlock = 16;

                //Количество байт
                byte[] dataD = new byte[packet.data.Length];

                //В цикле формируем блоки указанного размера...
                for (int i = 0; i < packet.data.Length; i += sizeBlock)
                {
                    byte[] data8bytes = new byte[sizeBlock];

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        data8bytes[k] = packet.data[k + i];
                    }

                    //...и дешифруем каждый блок в отдельности с помощью ключа
                    byte[] dataD8bytes = kuznyechik.decrypt(data8bytes, key);

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        dataD[k + i] = dataD8bytes[k];
                    }
                }

                //Декодируем расшифрованный набор байт в текст
                result = Encoding.GetEncoding(866).GetString(dataD);
                result = result.Replace("┼", "");     //Убираем симвлоы заполнения блока
                break;

            case "Магма":
                //Аналогично Кузнечику
                Magma magma = new Magma();
                sizeBlock = 8;
                dataD     = magma.Decode(packet.data, key);
                result    = Encoding.GetEncoding(866).GetString(dataD);
                result    = result.Replace("┼", "");
                break;

            case "AES":
                //Аналогично Кузнечику
                sizeBlock = 16;

                Aes aes = Aes.Create();
                aes.Mode      = CipherMode.ECB;
                aes.KeySize   = 256;
                aes.BlockSize = sizeBlock * 8;
                aes.Key       = key;
                aes.Padding   = PaddingMode.Zeros;

                ICryptoTransform encryptor = aes.CreateDecryptor();

                dataD  = encryptor.TransformFinalBlock(packet.data, 0, packet.data.Length);
                result = Encoding.GetEncoding(866).GetString(dataD);
                result = result.Replace("┼", "");
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }
Пример #21
0
        public override bool Place(Point origin, StructureMap structures)
        {
            if (_tiles[origin.X, origin.Y].active())
            {
                return(false);
            }
            var length1 = _sourceMagmaMap.GetLength(0);
            var length2 = _sourceMagmaMap.GetLength(1);
            var index1  = length1 / 2;
            var index2  = length2 / 2;

            origin.X -= index1;
            origin.Y -= index2;
            for (var index3 = 0; index3 < length1; ++index3)
            {
                for (var index4 = 0; index4 < length2; ++index4)
                {
                    var i = index3 + origin.X;
                    var j = index4 + origin.Y;
                    _sourceMagmaMap[index3, index4] =
                        Magma.CreateEmpty(WorldGen.SolidTile(i, j) ? 4f : 1f);
                    _targetMagmaMap[index3, index4] = _sourceMagmaMap[index3, index4];
                }
            }

            var max1 = index1;
            var min1 = index1;
            var max2 = index2;
            var min2 = index2;

            for (var index3 = 0; index3 < 300; ++index3)
            {
                for (var index4 = max1; index4 <= min1; ++index4)
                {
                    for (var index5 = max2; index5 <= min2; ++index5)
                    {
                        var sourceMagma1 = _sourceMagmaMap[index4, index5];
                        if (sourceMagma1.IsActive)
                        {
                            var num1 = 0.0f;
                            var zero = Vector2.Zero;
                            for (var index6 = -1; index6 <= 1; ++index6)
                            {
                                for (var index7 = -1; index7 <= 1; ++index7)
                                {
                                    if (index6 != 0 || index7 != 0)
                                    {
                                        var vector2 = new Vector2(index6, index7);
                                        vector2.Normalize();
                                        var sourceMagma2 =
                                            _sourceMagmaMap[index4 + index6, index5 + index7];
                                        if (sourceMagma1.Pressure > 0.00999999977648258 &&
                                            !sourceMagma2.IsActive)
                                        {
                                            if (index6 == -1)
                                            {
                                                max1 = Utils.Clamp(index4 + index6, 1, max1);
                                            }
                                            else
                                            {
                                                min1 = Utils.Clamp(index4 + index6, min1, length1 - 2);
                                            }
                                            if (index7 == -1)
                                            {
                                                max2 = Utils.Clamp(index5 + index7, 1, max2);
                                            }
                                            else
                                            {
                                                min2 = Utils.Clamp(index5 + index7, min2, length2 - 2);
                                            }
                                            _targetMagmaMap[index4 + index6, index5 + index7] =
                                                sourceMagma2.ToFlow();
                                        }

                                        var pressure = sourceMagma2.Pressure;
                                        num1 += pressure;
                                        zero += pressure * vector2;
                                    }
                                }
                            }

                            var num2 = num1 / 8f;
                            if (num2 > (double)sourceMagma1.Resistance)
                            {
                                var num3     = zero.Length() / 8f;
                                var pressure = Math.Max(0.0f,
                                                        (float)(Math.Max(num2 - num3 - sourceMagma1.Pressure, 0.0f) +
                                                                (double)num3 + sourceMagma1.Pressure * 0.875) -
                                                        sourceMagma1.Resistance);
                                _targetMagmaMap[index4, index5] = Magma.CreateFlow(pressure,
                                                                                   Math.Max(0.0f, sourceMagma1.Resistance - pressure * 0.02f));
                            }
                        }
                    }
                }

                if (index3 < 2)
                {
                    _targetMagmaMap[index1, index2] = Magma.CreateFlow(25f, 0.0f);
                }
                Utils.Swap(ref _sourceMagmaMap, ref _targetMagmaMap);
            }

            var flag1 = origin.Y + index2 > WorldGen.lavaLine - 30;
            var flag2 = false;

            for (var index3 = -50; index3 < 50 && !flag2; ++index3)
            {
                for (var index4 = -50; index4 < 50 && !flag2; ++index4)
                {
                    if (_tiles[origin.X + index1 + index3, origin.Y + index2 + index4].active())
                    {
                        switch (_tiles[origin.X + index1 + index3, origin.Y + index2 + index4].type)
                        {
                        case 147:
                        case 161:
                        case 162:
                        case 163:
                        case 200:
                            flag1 = false;
                            flag2 = true;
                            continue;

                        default:
                            continue;
                        }
                    }
                }
            }

            for (var index3 = max1; index3 <= min1; ++index3)
            {
                for (var index4 = max2; index4 <= min2; ++index4)
                {
                    var sourceMagma = _sourceMagmaMap[index3, index4];
                    if (sourceMagma.IsActive)
                    {
                        var tile = _tiles[origin.X + index3, origin.Y + index4];
                        if (Math.Max(
                                1f - Math.Max(0.0f,
                                              (float)(Math.Sin((origin.Y + index4) * 0.400000005960464) *
                                                      0.699999988079071 + 1.20000004768372) *
                                              (float)(0.200000002980232 + 0.5 / Math.Sqrt(Math.Max(0.0f,
                                                                                                   sourceMagma.Pressure - sourceMagma.Resistance)))),
                                sourceMagma.Pressure / 15f) > 0.349999994039536 +
                            (WorldGen.SolidTile(origin.X + index3, origin.Y + index4) ? 0.0 : 0.5))
                        {
                            if (TileID.Sets.Ore[tile.type])
                            {
                                tile.ResetToType(tile.type);
                            }
                            else
                            {
                                tile.ResetToType(368);
                            }
                            tile.wall = 180;
                        }
                        else if (sourceMagma.Resistance < 0.00999999977648258)
                        {
                            WorldUtils.ClearTile(origin.X + index3, origin.Y + index4, false);
                            tile.wall = 180;
                        }

                        if (tile.liquid > 0 && flag1)
                        {
                            tile.liquidType(1);
                        }
                    }
                }
            }

            var point16List = new List <Point16>();

            for (var index3 = max1; index3 <= min1; ++index3)
            {
                for (var index4 = max2; index4 <= min2; ++index4)
                {
                    if (_sourceMagmaMap[index3, index4].IsActive)
                    {
                        var num1 = 0;
                        var num2 = index3 + origin.X;
                        var num3 = index4 + origin.Y;
                        if (WorldGen.SolidTile(num2, num3))
                        {
                            for (var index5 = -1; index5 <= 1; ++index5)
                            {
                                for (var index6 = -1; index6 <= 1; ++index6)
                                {
                                    if (WorldGen.SolidTile(num2 + index5, num3 + index6))
                                    {
                                        ++num1;
                                    }
                                }
                            }

                            if (num1 < 3)
                            {
                                point16List.Add(new Point16(num2, num3));
                            }
                        }
                    }
                }
            }

            foreach (var point16 in point16List)
            {
                var x = (int)point16.X;
                var y = (int)point16.Y;
                WorldUtils.ClearTile(x, y, true);
                _tiles[x, y].wall = 180;
            }

            point16List.Clear();
            for (var index3 = max1; index3 <= min1; ++index3)
            {
                for (var index4 = max2; index4 <= min2; ++index4)
                {
                    var sourceMagma = _sourceMagmaMap[index3, index4];
                    var index5      = index3 + origin.X;
                    var index6      = index4 + origin.Y;
                    if (sourceMagma.IsActive)
                    {
                        WorldUtils.TileFrame(index5, index6, false);
                        WorldGen.SquareWallFrame(index5, index6, true);
                        if (_random.Next(8) == 0 && _tiles[index5, index6].active())
                        {
                            if (!_tiles[index5, index6 + 1].active())
                            {
                                WorldGen.PlaceTight(index5, index6 + 1, 165, false);
                            }
                            if (!_tiles[index5, index6 - 1].active())
                            {
                                WorldGen.PlaceTight(index5, index6 - 1, 165, false);
                            }
                        }

                        if (_random.Next(2) == 0)
                        {
                            Tile.SmoothSlope(index5, index6, true);
                        }
                    }
                }
            }

            return(true);
        }
Пример #22
0
 protected override void Benchmark(int[] array, Stopwatch t, ref int count)
 {
     t.Start();
     count = array.Select(p => Magma.IsPrime(p)).Count(p => p);
     t.Stop();
 }
Пример #23
0
        /// <summary>
        /// Шифратор
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private Packet Encrypt(string data)
        {
            byte[] result;
            byte[] dataBytes;
            int    sizeBlock;

            string cipher = comboBox1.SelectedItem.ToString();

            switch (cipher)
            {
            case "Нет":
                result = Encoding.GetEncoding(866).GetBytes(data);
                break;

            case "Кузнечик":
                Kuznyechik kuznyechik = new Kuznyechik();
                sizeBlock = 16;

                while (data.Length % sizeBlock != 0)
                {
                    data += "┼";
                }

                dataBytes = Encoding.GetEncoding(866).GetBytes(data);
                result    = new byte[dataBytes.Length];

                for (int i = 0; i < dataBytes.Length; i += sizeBlock)
                {
                    byte[] data8bytes = new byte[sizeBlock];

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        data8bytes[k] = dataBytes[k + i];
                    }

                    byte[] dataE8bytes = kuznyechik.encrypt(data8bytes, key);

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        result[k + i] = dataE8bytes[k];
                    }
                }
                break;

            case "Магма":
                Magma magma = new Magma();
                sizeBlock = 8;

                while (data.Length % sizeBlock != 0)
                {
                    data += "┼";
                }

                dataBytes = Encoding.GetEncoding(866).GetBytes(data);
                result    = magma.Encode(dataBytes, key);
                break;

            case "AES":
                sizeBlock = 16;

                Aes aes = Aes.Create();
                aes.Mode      = CipherMode.ECB;
                aes.KeySize   = 256;
                aes.BlockSize = sizeBlock * 8;
                aes.Key       = key;
                aes.Padding   = PaddingMode.Zeros;

                ICryptoTransform encryptor = aes.CreateEncryptor();

                while (data.Length % sizeBlock != 0)
                {
                    data += "┼";
                }

                dataBytes = Encoding.GetEncoding(866).GetBytes(data);
                result    = encryptor.TransformFinalBlock(dataBytes, 0, sizeBlock);
                break;

            default:
                result = null;
                break;
            }

            Packet packet = new Packet();

            packet.data   = result;
            packet.cipher = cipher;
            return(packet);
        }
Пример #24
0
        /// <summary>
        /// Дешифратор
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        static string Decrypt(Packet packet)
        {
            string result = "";

            byte[] dataD;
            int    sizeBlock;

            switch (packet.cipher)
            {
            case "Нет":
            case null:
                result = Encoding.GetEncoding(866).GetString(packet.data);
                break;

            case "Кузнечик":
                Kuznyechik kuznyechik = new Kuznyechik();
                sizeBlock = 16;
                dataD     = new byte[packet.data.Length];

                for (int i = 0; i < packet.data.Length; i += sizeBlock)
                {
                    byte[] data8bytes = new byte[sizeBlock];

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        data8bytes[k] = packet.data[k + i];
                    }

                    byte[] dataD8bytes = kuznyechik.decrypt(data8bytes, key);

                    for (int k = 0; k < sizeBlock; k++)
                    {
                        dataD[k + i] = dataD8bytes[k];
                    }
                }

                result = Encoding.GetEncoding(866).GetString(dataD);
                result = result.Replace("┼", "");
                break;

            case "Магма":
                Magma magma = new Magma();
                dataD  = magma.Decode(packet.data, key);
                result = Encoding.GetEncoding(866).GetString(dataD);
                result = result.Replace("┼", "");
                break;

            case "AES":
                sizeBlock = 16;

                Aes aes = Aes.Create();
                aes.Mode      = CipherMode.ECB;
                aes.KeySize   = 256;
                aes.BlockSize = sizeBlock * 8;
                aes.Key       = key;
                aes.Padding   = PaddingMode.Zeros;

                ICryptoTransform decryptor = aes.CreateDecryptor();

                dataD  = decryptor.TransformFinalBlock(packet.data, 0, packet.data.Length);
                result = Encoding.GetEncoding(866).GetString(dataD);
                result = result.Replace("┼", "");
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }