Exemplo n.º 1
0
    public static RandomTable MakeRandomTable()
    {
        RandomTable table = new RandomTable();

        table.Init();
        return(table);
    }
        public async Task <DalResult> UpdateRandomTable(RandomTable table)
        {
            try
            {
                var result = await db.RandomTable.UpdateAsync(table);

                await db.TableEntry.DeleteAllForTableAsync(table.Id);

                if (table.Entries.Count > 0)
                {
                    foreach (var entry in table.Entries)
                    {
                        if (entry.Id == Guid.Empty)
                        {
                            entry.FK_RandomTable = table.Id;
                            entry.Id             = await db.TableEntry.InsertAsync(entry);
                        }
                        else
                        {
                            await db.TableEntry.UpdateAsync(entry);
                        }
                    }
                }

                return(new DalResult(result ? DalStatus.Success : DalStatus.Unknown));
            }
            catch (Exception e)
            {
                Log.Error(e, "Exception updating table id {Id}.", table.Id);
                return(new DalResult(DalStatus.Unknown, "Error updating table"));
            }
        }
Exemplo n.º 3
0
 private void InitTileTypeRandomTable()
 {
     tileTypeRandomTable = RandomTable.MakeRandomTable();
     for (int i = 0, max = DataManager.GetInstance().GetTileTableListCount(); i < max; i++)
     {
         PuzzleTable table = DataManager.GetInstance().GetTileTable(i);
         tileTypeRandomTable.AddRate(table.idx, table.rate);
     }
 }
Exemplo n.º 4
0
    bool SetNoiseCS_3D(NoiseModule _noise, ComputeBuffer _res)
    {
        if (_noise == null || _res == null)
        {
            return(false);
        }

        string      path     = "TiliedCurlNoise3D";
        string      kanel    = "CS_CurlNoise3D";
        RandomTable randFunc = SetCommonRandomTable;

        ComputeShader cs = Resources.Load <ComputeShader>(path);

        if (cs == null)
        {
            return(false);
        }

        int kID = cs.FindKernel(kanel);

        ComputeBuffer rtBuffer = null;

        if (randFunc != null)
        {
            rtBuffer = randFunc.Invoke(cs, kID);
        }

        cs.SetInt("Octaves", _noise.bFBM ? _noise.iOctaves : 1);
        cs.SetFloat("Persistence", _noise.fPersistence);
        cs.SetFloat("Scale", _noise.fScale);
        cs.SetFloat("Period", _noise.iPeriod);
        cs.SetInt("TexWidth", mTexSize);
        cs.SetInt("TexHeight", mTexSize);
        cs.SetInt("TexDepth", mTexSize);

        cs.SetBuffer(kID, "Result", _res);

        uint sizeX, sizeY, sizeZ;

        cs.GetKernelThreadGroupSizes(
            kID,
            out sizeX,
            out sizeY,
            out sizeZ
            );

        cs.Dispatch(kID, mTexSize / (int)sizeX, mTexSize / (int)sizeY, mTexSize / (int)sizeZ);

        if (rtBuffer != null)
        {
            rtBuffer.Release();
            rtBuffer = null;
        }

        return(true);
    }
Exemplo n.º 5
0
    bool GetComputerShader_3D(eNoiseType _type, out string _path, out string _kanel, out RandomTable _randFunc)
    {
        bool res = false;

        _path     = string.Empty;
        _kanel    = string.Empty;
        _randFunc = null;

        switch (_type)
        {
        case eNoiseType.Perlin:
            _path     = "TiliedPerlinNoise3D";
            _kanel    = "CS_PerlinNoise3D";
            _randFunc = SetPerlinRandomTable;
            res       = true;
            break;

        case eNoiseType.Voronoi:
            _path     = "TiliedVoronoi3D";
            _kanel    = "CS_Voronoi3D";
            _randFunc = SetCommonRandomTable;
            res       = true;
            break;

        case eNoiseType.Cellular:
            _path     = "TiliedCellularNoise3D";
            _kanel    = "CS_CellularNoise3D";
            _randFunc = SetCommonRandomTable;
            res       = true;
            break;

        case eNoiseType.PerlinWorley:
            _path     = "TiliedPerlinWorley3D";
            _kanel    = "CS_PerlinWorley3D";
            _randFunc = SetPerlinWorleyRandomTable;
            res       = true;
            break;

        case eNoiseType.WhiteNoise:
            _path     = "WhiteNoise3D";
            _kanel    = "CS_WhiteNoise3D";
            _randFunc = SetCommonRandomTable;
            res       = true;
            break;
        }

        return(res);
    }
Exemplo n.º 6
0
        public static VoronoiNoise <T> Make(Size rect, int scale, Random rnd, RandomTable <T> elems)
        {
            var cells   = new Grid <T>(new Size((int)Math.Ceiling(rect.X / (double)scale), (int)Math.Ceiling(rect.Y / (double)scale)));
            var centers = new Grid <Vec>(cells.Size);

            foreach (var i in cells.Ids())
            {
                cells[i]   = elems.GetRand(rnd);
                centers[i] = new Vec(i.X * scale + rnd.Next(scale), i.Y * scale + rnd.Next(scale));
            }

            return(new VoronoiNoise <T> {
                Scale = scale,
                Cells = cells,
                Centers = centers
            });
        }
Exemplo n.º 7
0
        public void ShouldReturnItemsWithTheFrequencySpecified()
        {
            var randomIncrement = 0;
            var randomTable = new RandomTable<int>(maxValue => randomIncrement++ % maxValue);

            randomTable.Add(5, 7);
            randomTable.Add(3, 2);
            randomTable.Add(7, 1);

            var results = randomTable
                .Sequence
                .Take(10)
                .ToArray();

            results.Count(r => r == 5).ShouldBe(7);
            results.Count(r => r == 3).ShouldBe(2);
            results.Count(r => r == 7).ShouldBe(1);
        }
Exemplo n.º 8
0
        public void ShouldReturnItemsWithTheFrequencySpecified()
        {
            var randomIncrement = 0;
            var randomTable     = new RandomTable <int>(maxValue => randomIncrement++ % maxValue);

            randomTable.Add(5, 7);
            randomTable.Add(3, 2);
            randomTable.Add(7, 1);

            var results = randomTable
                          .Sequence
                          .Take(10)
                          .ToArray();

            results.Count(r => r == 5).ShouldBe(7);
            results.Count(r => r == 3).ShouldBe(2);
            results.Count(r => r == 7).ShouldBe(1);
        }
Exemplo n.º 9
0
        static void QuickSortTestRandomTable()
        {
            //tworzenie tablicy bazowej
            RandomTable randomTable = new RandomTable();

            int[] _oBaseTable = randomTable.GenerateTab(200_000);

            //tworzenie obiektów sortujących
            QuickSortIteration quickSortIteration = new QuickSortIteration(_oBaseTable);
            QuickSortRecursion quickSortRecursion = new QuickSortRecursion(_oBaseTable);

            //pętla po typach algoryutmów sortujących
            for (int type = 0; type < 2; type++)
            {
                //wypisanie informacji dla każdego typu algorytmu
                switch (type)
                {
                case 0:
                    Console.WriteLine("QuickSortIteration");
                    break;

                case 1:
                    Console.WriteLine("QuickSortRecursion");
                    break;
                }

                //główna pętla wielkości sortowanych tablic
                for (int i = 50_000; i <= g_iBaseTabSize; i += 5_000)
                {
                    //określa który algorytm ma sortować
                    switch (type)
                    {
                    case 0:
                        quickSortIteration.MeasureSortTime(i);
                        break;

                    case 1:
                        quickSortRecursion.MeasureSortTime(i);
                        break;
                    }
                }
            }
        }
Exemplo n.º 10
0
        public NameGenerator(RandomNameConfiguration configuration)
        {
            _random = configuration.CreateRandom();
            _maleTable = new RandomTable<string>(_random.Next);
            _femaleTable = new RandomTable<string>(_random.Next);
            _surnameTable = new RandomTable<string>(_random.Next);

            _maxGivenNames = configuration.MaxGivenNames;

            var nameFiles = configuration.GetCensusDataFiles();
            var convention = configuration.GetFileTypeConvention();

            foreach (var nameData in nameFiles.Where(convention.ContainsMaleNames).SelectMany(f => f.NameData))
                _maleTable.Add(nameData.Name, nameData.Frequency);

            foreach (var nameData in nameFiles.Where(convention.ContainsFemaleNames).SelectMany(f => f.NameData))
                _femaleTable.Add(nameData.Name, nameData.Frequency);

            foreach (var nameData in nameFiles.Where(convention.ContainsSurnames).SelectMany(f => f.NameData))
                _surnameTable.Add(nameData.Name, nameData.Frequency);
        }
        public async Task <DalResult <Guid> > AddRandomTable(RandomTable table)
        {
            try
            {
                var id = await db.RandomTable.InsertAsync(table);

                if (table.Entries.Count > 0)
                {
                    foreach (var entry in table.Entries)
                    {
                        entry.FK_RandomTable = id;
                        entry.Id             = await db.TableEntry.InsertAsync(entry);
                    }
                }

                return(new DalResult <Guid>(DalStatus.Success, id));
            }
            catch (Exception e)
            {
                Log.Error(e, "Exception saving table {Name}.", table.Name);
                return(new DalResult <Guid>(DalStatus.Unknown, Guid.Empty, "Error saving table"));
            }
        }
Exemplo n.º 12
0
        public void Emit(ParticleProps particleProps)
        {
            m_ParticlesPool[m_PoolIndex].Active   = true;
            m_ParticlesPool[m_PoolIndex].Position = particleProps.Position;
            m_ParticlesPool[m_PoolIndex].Rotation = RandomTable.RandomFloat() * 5.0f * MathHelper.Pi;
            m_ParticlesPool[m_PoolIndex].Gravity  = particleProps.Gravity;
            // Velocity
            m_ParticlesPool[m_PoolIndex].Velocity    = particleProps.Velocity;
            m_ParticlesPool[m_PoolIndex].Velocity.x += particleProps.VelocityVariation.x * (RandomTable.RandomFloat() - 0.5f);
            m_ParticlesPool[m_PoolIndex].Velocity.y += particleProps.VelocityVariation.y * (RandomTable.RandomFloat() - 0.5f);

            // Color
            m_ParticlesPool[m_PoolIndex].ColorBegin = particleProps.ColorBegin;
            m_ParticlesPool[m_PoolIndex].ColorEnd   = particleProps.ColorEnd;

            m_ParticlesPool[m_PoolIndex].LifeTime      = particleProps.LifeTime;
            m_ParticlesPool[m_PoolIndex].LifeRemaining = particleProps.LifeTime;
            m_ParticlesPool[m_PoolIndex].SizeBegin     = particleProps.SizeBegin + particleProps.SizeVariation * (RandomTable.RandomFloat() - 0.5f);
            m_ParticlesPool[m_PoolIndex].SizeEnd       = particleProps.SizeEnd;

            m_ParticlesPool[m_PoolIndex].axisRot = new vec3((RandomTable.RandomInt() % 2), (RandomTable.RandomInt() * 0), (1 + RandomTable.RandomInt() % 2));

            m_PoolIndex = ++m_PoolIndex % m_ParticlesPool.Length;
        }
Exemplo n.º 13
0
        static void RandomTableTest()
        {
            //tworzenie tablicy bazowej
            RandomTable randomTable = new RandomTable();

            int[] _oBaseTable = randomTable.GenerateTab(g_iBaseTabSize);

            //tworzenie obiektów sortujących
            SelectionSort selectionSort = new SelectionSort(_oBaseTable);
            InsertionSort insertionSort = new InsertionSort(_oBaseTable);
            CocktailSort  cocktailSort  = new CocktailSort(_oBaseTable);
            HeapSort      heapSort      = new HeapSort(_oBaseTable);

            //pętla po typach algoryutmów sortujących
            for (int type = 0; type < 4; type++)
            {
                //wypisanie informacji dla każdego typu algorytmu
                switch (type)
                {
                case 0:
                    Console.WriteLine("SelectionSort");
                    break;

                case 1:
                    Console.WriteLine("InsertionSort");
                    break;

                case 2:
                    Console.WriteLine("CocktailSort");
                    break;

                case 3:
                    Console.WriteLine("HeapSort");
                    break;
                }

                //główna pętla wielkości sortowanych tablic
                for (int i = 50_000; i <= g_iBaseTabSize; i += 5_000)
                {
                    //określa który algorytm ma sortować
                    switch (type)
                    {
                    case 0:
                        selectionSort.MeasureSortTime(i);
                        break;

                    case 1:
                        insertionSort.MeasureSortTime(i);
                        break;

                    case 2:
                        cocktailSort.MeasureSortTime(i);
                        break;

                    case 3:
                        heapSort.MeasureSortTime(i);
                        break;
                    }
                }
            }
        }
 public Task <DalResult> UpdateRandomTable(RandomTable table)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 15
0
 public MonsterFactory()
 {
     BasePropabilities = RandomTable <string> .FromString("bat:2,zombie:3,firebat:1,skeleton:1");
 }
#pragma warning restore 1998

        private void SetUpTables()
        {
            var testTable = new RandomTable
            {
                Id          = Guid.Empty,
                Name        = "Test Table",
                Category    = "Test",
                Description = "Test",
                Enabled     = true,
                Entries     = new List <TableEntry>
                {
                    new TableEntry
                    {
                        Id             = Guid.NewGuid(),
                        FK_RandomTable = Guid.Empty,
                        Entry          = "Table entry 1",
                        UpperBound     = 1,
                        LowerBound     = 1,
                    },
                    new TableEntry
                    {
                        Id             = Guid.NewGuid(),
                        FK_RandomTable = Guid.Empty,
                        Entry          = "Table entry 2",
                        UpperBound     = 5,
                        LowerBound     = 2,
                    },
                    new TableEntry
                    {
                        Id             = Guid.NewGuid(),
                        FK_RandomTable = Guid.Empty,
                        Entry          = "Table entry 3",
                        UpperBound     = 6,
                        LowerBound     = 6,
                    },
                    new TableEntry
                    {
                        Id             = Guid.NewGuid(),
                        FK_RandomTable = Guid.Empty,
                        Entry          = "Table entry 4",
                        UpperBound     = 7,
                        LowerBound     = 7,
                    },
                }
            };

            tables["Test Table"] = testTable;

            var raceTable = new RandomTable
            {
                Id          = Guid.Empty,
                Name        = "race",
                Category    = "Test",
                Description = "Test",
                Enabled     = true,
                Entries     = new List <TableEntry>()
            };

            tables["race"] = raceTable;


            var lastNamesTable = new RandomTable
            {
                Id          = Guid.Empty,
                Name        = "Last Names",
                Category    = "Test",
                Description = "Test",
                Enabled     = true,
                Entries     = new List <TableEntry>()
            };

            tables["Last Names"] = raceTable;
        }
Exemplo n.º 17
0
 public WeaponFactory()
 {
     BasePropabilities = RandomTable <string> .FromString("dagger:3,ssword:2,lsword:5,axe:3,spear:5,mace:2,wshield:3,ishield:1,sbow:13,lbow:21,armour_leather:3,armour_chain:2,armour_plate:1,helmet:5,gloves:2,boots:2,ring:1,cloak:1,amulet:1,@resistance:3");
 }
 public Task <DalResult <Guid> > AddRandomTable(RandomTable table)
 {
     throw new System.NotImplementedException();
 }