public static float[,] Crossover(float[,] parentA, float[,] parentB)
        {
            if (parentA.Length != parentB.Length)
            {
                throw new ApplicationException("Corssover of two tables with different sizes is not allowed.");
            }

            var child = new float[parentA.GetLength(0), parentA.GetLength(1)];

            for (int i = 0; i < child.GetLength(0); i++)
            {
                for (int j = 0; j < child.GetLength(1); j++)
                {
                    if (CRandom.NextFloat() < 0.5f)
                    {
                        child[i, j] = parentA[i, j];
                    }
                    else
                    {
                        child[i, j] = parentB[i, j];
                    }
                }
            }

            return(child);
        }
Ejemplo n.º 2
0
        private static List <List <Person> > CreateRandomTables(int count)
        {
            var tables = new List <List <Person> >();

            for (var j = 0; j < count; j++)
            {
                var maleImage   = GameData.GetNextMaleImage();
                var femaleImage = GameData.GeNextFemaleImage();

                var boy = new Person
                {
                    Name    = GameData.GetNameById(maleImage),
                    Image   = maleImage,
                    Male    = true,
                    Gay     = false,
                    Hobbies = GenerateHobbies(CRandom.GetRandom(3, 9))
                };
                var girl = new Person
                {
                    Name    = GameData.GetNameById(maleImage),
                    Image   = femaleImage,
                    Male    = false,
                    Gay     = false,
                    Hobbies = GenerateHobbies(CRandom.GetRandom(3, 9))
                };

                tables.Add(new List <Person> {
                    boy, girl
                });
            }

            return(tables);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Läd das Ingame-Spiel
        /// </summary>
        public void LoadIngame(bool hard)
        {
            //Erstellen des Dungeons
            d = new Dungeon(new DungeonGenArgs()
            {
                CorridorWidth             = 6,
                Rooms                     = hard ? 15 : 10,
                LeaveConnectionPercentage = 0.25f,
                EnemiesPerRoom            = hard ? 6 : 3
            });

            //Resize der Rectangle für Performanz
            foreach (Rectangle r in d.Bounds)
            {
                r.Pos       *= 15;
                r.Size      *= 15;
                r.CenterPos *= 15;
            }
            thePlayer = new EntityPlayer(d.Bounds);

            rnd                = new CRandom(d.Args.Seed);
            thePlayer          = new EntityPlayer(d.Bounds);
            thePlayer.Position = d.StartRoom.CenterPos *= 15;
            player             = thePlayer;
            Entities.Add(thePlayer);
            path = new Path(thePlayer.GridPosition, d.StartRoom.CenterPos / 15f, d);

            SpawnEnemies();

            ingameGui = new GuiIngame(this);
            isIngame  = true;
        }
Ejemplo n.º 4
0
 public Field(int x, int y, CRandom rnd)
 {
     this.X   = x;
     this.Y   = y;
     this.rnd = rnd;
     Type     = FieldType.Nothing;
 }
Ejemplo n.º 5
0
        public void HobbyLoop()
        {
            Hobby.alpha = 0;

            if (Person.Hobbies.Count == 0)
            {
                return;
            }

            if (Engine.State != GameState.Playing)
            {
                TaskScheduler.CreateTask(HobbyLoop, Engine.TaskId, 1 + CRandom.GetRandom(200) / 100f);
                return;
            }

            if (_hobby == Person.Hobbies.Count)
            {
                _hobby = 0;
            }

            var duration = 3 + CRandom.GetRandom(300) / 100f;

            Hobby.spriteName = Convert.ToString(Person.Hobbies[_hobby++]);
            TweenAlpha.Begin(Hobby.gameObject, 0.4f, 1);
            TaskScheduler.CreateTask(() => TweenAlpha.Begin(Hobby.gameObject, 0.4f, 0), Engine.TaskId, duration);
            TaskScheduler.CreateTask(HobbyLoop, Engine.TaskId, duration + 1);
        }
Ejemplo n.º 6
0
        protected override void UpdateSubRoutine()
        {
            if (SubRoutineTimeRemaining > 0f)
            {
                SubRoutineTimeRemaining -= Time.deltaTime;
            }
            else
            {
                var chanceOfRetreatingRoutine = CRandom.Next(1, 4);
                SubRoutineTimeRemaining = CRandom.Nextf(MinRoutineTime, MaxRoutineTime);

                if (chanceOfRetreatingRoutine <= 1)
                {
                    CurrenMovementSubRoutineType = MovementSubRoutineType.MovingLeft;
                }
                else if (chanceOfRetreatingRoutine <= 2)
                {
                    CurrenMovementSubRoutineType = MovementSubRoutineType.MovingRight;
                }
                else
                {
                    CurrenMovementSubRoutineType = MovementSubRoutineType.MovingBackward;;
                }
            }
        }
Ejemplo n.º 7
0
        public static string GetBackground()
        {
            var backs = new List <string> {
                "CoffeeShop", "Attic", "SushiBar"
            };

            return(backs[CRandom.GetRandom(backs.Count)]);
        }
Ejemplo n.º 8
0
        public void PlayEffect(List <AudioClip> clips, bool reserved = false)
        {
            if (clips.Count == 0)
            {
                return;
            }

            PlayEffect(clips[CRandom.GetRandom(clips.Count)]);
        }
 private void Mutate(ref float[] valuesToMutate, float chanceOfMutation, float maxAddeValue = 1.0f)
 {
     for (int i = 0; i < valuesToMutate.GetLength(0); i++)
     {
         if (CRandom.NextFloat() < chanceOfMutation)
         {
             valuesToMutate[i] += CRandom.NextFloat(-maxAddeValue, maxAddeValue);
         }
     }
 }
Ejemplo n.º 10
0
        private void GenerateWords()
        {
            var rnd = new System.Random();

            _activeWords.Clear();
            var wordSource = Profile.Instance.Categories.Where(c => Profile.Instance.ActiveCatigories.Contains(c.Id)).SelectMany(c => c.Words)
                             .OrderBy(c => CRandom.GetRandom()).ToList();

            _activeWords.AddRange(wordSource);
            _activeIndex = 0;
        }
Ejemplo n.º 11
0
        private void PlayInGameNext(AudioClip clip)
        {
            AudioSource.Stop();
            AudioSource.clip = clip;
            AudioSource.loop = false;
            AudioSource.Play();

            var nexts = Music.Where(i => i != clip).ToList();
            var next  = nexts[CRandom.GetRandom(0, nexts.Count)];

            TaskScheduler.Kill(888);
            TaskScheduler.CreateTask(() => PlayInGameNext(next), 888, clip.length);
        }
 protected override void UpdateSubRoutine()
 {
     if (CurrentSightRoutineDelay > 0f)
     {
         CurrentSightRoutineDelay -= Time.deltaTime;
     }
     else if (CurrenSightSubRoutineType == SightSubRoutineType.LookForward)
     {
         var nextSightRoutine = CRandom.Next(1, 3);
         CurrenSightSubRoutineType =
             nextSightRoutine <= 1 ? SightSubRoutineType.LookLeft : SightSubRoutineType.LookRight;
     }
 }
Ejemplo n.º 13
0
        public virtual void OnEnable()
        {
            _time = Time.time;

            if (RandomPeriod)
            {
                Period = CRandom.GetRandom(360);
            }

            if (RandomSpeed)
            {
                Speed *= CRandom.GetRandom(100) / 100f;
            }
        }
Ejemplo n.º 14
0
        public void Randomize()
        {
            for (int i = 0; i < wages.GetLength(0); i++)
            {
                for (int j = 0; j < wages.GetLength(1); j++)
                {
                    this.wages[i, j] = CRandom.NextFloat(-1.0f, 1.0f);
                }
            }

            for (int i = 0; i < this.biasesInOutputLayer.Length; i++)
            {
                this.biasesInOutputLayer[i] = CRandom.NextFloat(-1.0f, 1.0f);
            }
        }
Ejemplo n.º 15
0
        public Dungeon(DungeonGenArgs args = null)
        {
            this.Args = args ?? new DungeonGenArgs();
            rnd       = new CRandom(this.Args.Seed);
            Fields    = new Field[(int)this.Args.Size.X, (int)this.Args.Size.Y];
            for (int x = 0; x < Fields.GetLength(0); x++)
            {
                for (int y = 0; y < Fields.GetLength(1); y++)
                {
                    Fields[x, y] = new Field(x, y, rnd);
                }
            }

            Generate();
        }
Ejemplo n.º 16
0
        private void PlaySound(TypePickable weaponType)
        {
            switch (weaponType)
            {
            case TypePickable.Shotgun:
                shotgunShootSound.Play();
                break;

            case TypePickable.Uzi:
                uziShootSounds[CRandom.Next(0, 2)].Play();
                break;

            default:
                starterWeaponShootSounds[CRandom.Next(0, 3)].Play();
                break;
            }
        }
Ejemplo n.º 17
0
        private static List <List <Person> > Shuffle(List <List <Person> > tables)
        {
            foreach (var table in tables)
            {
                if (CRandom.Chance(0.5f))
                {
                    table.Reverse();
                }
            }

            if (Settings.Debug)
            {
                Debug.Log(GetFormation(tables));
            }

            return(tables.Shuffle());
        }
Ejemplo n.º 18
0
        /// <summary>Initializes of RandomGenerator.</summary>
        /// <param name="randGen">Type of random generator:
        /// 0 Mersenne Twister, 1 O'Neill, 2 C std, 3 XorShift, 4 C# std, 5 C# strong.</param>
        /// <param name="normGen">Type of Gauss generator:
        /// -1 no generator, 0 Abramowitz and Stegun, 1 Central Limit Theorem,
        /// 2 Fog, 3Marsaglia, 4 C/C# std</param>
        /// <param name="isExp">True if include lognorm generation</param>
        /// <param name="isStdLogNorm">True if use C++ standard lognorm generation</param>
        /// <param name="distVars">Gauss or lognorm mean and sigma</param>
        /// <param name="ssVars">Size selection distribution mean and sigma, or null if size selection is inactive</param>
        /// <returns>False if extern CRandom dll is not found, otherwise true</returns>
        public static bool Init(int randGen, int normGen, bool isExp, bool isStdLogNorm,
                                float[] distVars, int[] ssVars)
        {
            Library  = randGen < FIRST_IND_CSH ? ON_C : (randGen == FIRST_IND_CSH + 1 ? ON_SCH_STRONG : ON_CSH);
            IsExp    = isExp;
            DistVars = distVars;
            if (normGen == -1 && !isExp)
            {
                DistVars[0] = 0; DistVars[1] = 1000;
            }

            if (Library == ON_C)
            {
                if (System.IO.File.Exists(CRandom.FullDllFile))
                {
                    CRandom.Init(randGen, normGen, isExp, isStdLogNorm, distVars, ssVars);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                RandomNumb = GetRandom;
                CshStrongRandomGen.RecordGaussGen(normGen);
                Distrib = Distribs[normGen + 1];
            }
            if (ssVars != null)     // size selection is able
            {
                ssMean = ssVars[0];
                //ssDVariance = 2 * ssVars[1] * ssVars[1];
                //ssFactor = ssVars[1] * Math.Sqrt(2 * Math.PI);
                //ssAlignRatio = 2.5 * ssVars[1];

                ssFactor0 = (float)(ssVars[1] * Math.Sqrt(2));
                ssFactor1 = 2.5f / (float)Math.Sqrt(2 * Math.PI);
            }
            else
            {
                ssMean = 0;
            }

            return(true);
        }
        public void Randomize()
        {
            CRandom.Randmize(ref this.wagesBetweenInputAndFirstHiddenLayer);

            for (int i = 0; i < this.wagesBetweenHiddenLayers.Length; i++)
            {
                CRandom.Randmize(ref this.wagesBetweenHiddenLayers[i]);
            }

            for (int i = 0; i < this.biasesInHiddenLayers.Length; i++)
            {
                CRandom.Randmize(ref this.biasesInHiddenLayers[i]);
            }

            CRandom.Randmize(ref this.wagesBetweenLastHiddenAndOutputLayer);

            CRandom.Randmize(ref this.biasesInOutputLayer);
        }
Ejemplo n.º 20
0
        public void Mutate(float chanceOfMutation, float maxAddeValue = 1.0f)
        {
            for (int i = 0; i < wages.GetLength(0); i++)
            {
                for (int j = 0; j < wages.GetLength(1); j++)
                {
                    if (CRandom.NextFloat() < chanceOfMutation)
                    {
                        wages[i, j] += CRandom.NextFloat(-maxAddeValue, maxAddeValue);
                    }
                }
            }

            for (int i = 0; i < this.biasesInOutputLayer.Length; i++)
            {
                if (CRandom.NextFloat() < chanceOfMutation)
                {
                    this.biasesInOutputLayer[i] += CRandom.NextFloat(-maxAddeValue, maxAddeValue);
                }
            }
        }
Ejemplo n.º 21
0
        public void ScheduleFix()
        {
            if (Time.timeScale > 0)
            {
                var nexts = Music.Where(i => i != AudioSource.clip).ToList();
                var next  = nexts[CRandom.GetRandom(0, nexts.Count)];

                if (AudioSource.isPlaying)
                {
                    TaskScheduler.Kill(888);
                    TaskScheduler.CreateTask(() => PlayInGameNext(next), 888, AudioSource.clip.length - AudioSource.time);
                }
                else
                {
                    PlayInGameNext(next);
                }
            }
            else
            {
                TaskScheduler.Kill(888);
            }
        }
Ejemplo n.º 22
0
 //* -----------------------------------------------------------------------*
 /// <summary>指定のシード値を使用し、乱数ジェネレータをリセットします。</summary>
 ///
 /// <param name="nSeed">
 /// <para>擬似乱数系列の開始値を計算するために使用する数値。</para>
 /// <para>負数を指定した場合、その数値の絶対値が使用されます。</para>
 /// </param>
 /// <exception cref="System.OverflowException">
 /// <para><c>Seed</c>>が<c>Int32.MinValue</c>です。</para>
 /// <para>これは、絶対値が計算されるときにオーバーフローの原因となります。</para>
 /// </exception>
 public static void reset(int nSeed)
 {
     m_nSeed = nSeed;
     random  = new CRandom(nSeed);
 }
Ejemplo n.º 23
0
 private void StartSightRoutineDelay()
 {
     CurrentSightRoutineDelay  = CRandom.Nextf(MinSightRoutineDelay, MaxSightRoutineDelay);
     CurrenSightSubRoutineType = SightSubRoutineType.LookForward;
 }
Ejemplo n.º 24
0
 public void Start()
 {
     _stopClips[GameMusic.Ingame] = CRandom.GetRandom(IngameMusic.Count);
     ContiniousPlay();
 }
Ejemplo n.º 25
0
        private static List <List <Person> > InitializeTables(Level level)
        {
            GameData.Initialize();

            var tables     = new List <List <Person> >();
            var boys       = new List <Person>();
            var girls      = new List <Person>();
            var hobbyShift = CRandom.GetRandom(0, 10);

            for (var i = 0; i < level.TableNumber; i++)
            {
                for (var j = 0; j < level.MaleHobbies[i].Count; j++)
                {
                    level.MaleHobbies[i][j] = (Hobby)IncMod((int)level.MaleHobbies[i][j], hobbyShift, GameData.Hobbies.Count);
                }

                for (var j = 0; j < level.FemaleHobbies[i].Count; j++)
                {
                    level.FemaleHobbies[i][j] = (Hobby)IncMod((int)level.FemaleHobbies[i][j], hobbyShift, GameData.Hobbies.Count);
                }

                tables.Add(new List <Person>());

                var maleImage   = GameData.GetNextMaleImage();
                var femaleImage = GameData.GeNextFemaleImage();

                boys.Add(new Person
                {
                    Name    = GameData.GetNameById(maleImage),
                    Image   = maleImage,
                    Male    = true,
                    Hobbies = level.MaleHobbies[i]
                });
                girls.Add(new Person
                {
                    Name    = GameData.GetNameById(femaleImage),
                    Image   = femaleImage,
                    Male    = false,
                    Hobbies = level.FemaleHobbies[i]
                });
            }

            if (level.Formation != null)
            {
                for (var i = 0; i < level.Formation.Count; i++)
                {
                    tables[i] = new List <Person>
                    {
                        boys[level.Formation[i][0]],
                        girls[level.Formation[i][1]]
                    };
                }

                return(Shuffle(tables));
            }

            for (var i = 0; i < level.TableNumber; i++)
            {
                tables[i] = new List <Person> {
                    boys[i], girls[i]
                };
            }

            List <List <Person> > worst, best;
            int max, complexity;

            Analize(tables, out worst, out best, out max, out complexity);

            if (max != Level.Target && Level.Type != LevelType.Memo)
            {
                throw new Exception(Convert.ToString(max));
            }

            var suffle = Shuffle(worst);

            if (level.Type == LevelType.Swap)
            {
                level.Swaps = CalcSwaps(suffle, best, max);
            }

            return(suffle);
        }
Ejemplo n.º 26
0
        /// <summary>Fills data by current distribution.</summary>
        /// <param name="numbers">Data that should be filled</param>
        /// <param name="cnt">Number or repetitions. Returned the number of random generator calls.</param>
        /// <returns>Average Y value.</returns>
        public static float GetDistrib(Numbers numbers, ref int cnt)
        {
            GenCallCnt = 0;
            if (Library == ON_C)
            {
                float res = CRandom.GetDistrib(
                    numbers != null ? numbers.Data : null, ref cnt, ref GenCallCnt);
                cnt = GenCallCnt;
                return(res);
            }
            else if (Library == ON_SCH_STRONG)
            {
                CshStrongRandomGen gen = new CshStrongRandomGen(cnt);
                RandomNumb = gen.GetNext;
            }
            decimal sum = 0;
            int     val;
            int     actualCnt = 0;
            double  dval;
            float   ssDev; // result of inverse normal distrib
            int     min, max;

            for (int i = 0; i < cnt; i++)
            {
                dval = Distrib() * DistVars[1] + DistVars[0];
                if (IsExp)  // lognorm is able
                {
                    val = (int)Math.Exp(dval);

                    if (ssMean > 0)                      // size selection is able
                    // === simple method
                    //if (GetRandom() > ssAlignRatio *
                    //    Math.Exp(-Math.Pow(dval - ssMean, 2) / ssDVariance) / ssFactor)
                    //    continue;		// filter by size selection

                    // === method with using min and max
                    {
                        ssDev = ssFactor0 * (float)Math.Sqrt(Math.Log(ssFactor1 / GetRandom()));
                        min   = (int)(ssMean - ssDev);
                        max   = (int)(ssMean + ssDev);
                        if (val < min || val > max)
                        {
                            continue;                                   // filter by size selection
                        }
                    }
                }
                else // lognorm is disable
                {
                    val = (int)dval;
                    // round up val: otherwise all values will be round down during casting to int.
                    // in this case the distribution will not only be inaccurate,
                    // but worse - values less than 1 will be rounded to 0,
                    // which leads to a falsely large number of zero points.
                    // The variant val = (int)Math.Round(dval, 0) is much slower
                    if (dval > 0)
                    {
                        if (dval - val >= 0.5)
                        {
                            val++;
                        }
                    }                                                   // round up positives
                    else
                    {
                        if (dval - val <= -0.5)
                        {
                            val--;
                        }
                    }                                           // round up negatieves
                }
                sum += val;
                if (numbers != null)
                {
                    numbers.Data[actualCnt] = val;
                }
                actualCnt++;
            }
            cnt = GenCallCnt;
            return((float)sum / actualCnt);
        }
Ejemplo n.º 27
0
 public void Awake()
 {
     Refresh();
     PlayInGameNext(Music[CRandom.GetRandom(0, Music.Length)]);
 }
Ejemplo n.º 28
0
 public ServerManager(string host, string user, string password)
 {
     rnd        = new CRandom();
     connection = new DBConnection(host, user, password);
     InitDB();
 }
Ejemplo n.º 29
0
        private static void Analize(List <List <Person> > tables, out List <List <Person> > worst, out List <List <Person> > best, out int max, out int complexity)
        {
            var combinations = new List <List <List <Person> > >();
            var boys         = tables.Select(p => p.Single(c => c.Male)).ToList();
            var girls        = tables.Select(p => p.Single(c => !c.Male)).ToList();

            if (Settings.Debug)
            {
                Dump(boys, girls);
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            GetCombinations(boys, girls, ref combinations, new List <List <Person> >());

            Debug.Log("combinations.Count = " + combinations.Count);

            var  mins = new List <int>();
            var  maxs = new List <int>();
            var  min  = 999;
            long sum  = 0;

            max = complexity = 0;

            var sympathies = GetSympathies(boys, girls);

            for (var j = 0; j < combinations.Count; j++)
            {
                var s = 0;

                foreach (var table in combinations[j])
                {
                    var sympathy = sympathies[table[0]][table[1]];

                    s += sympathy;
                }

                if (s < min)
                {
                    min  = s;
                    mins = new List <int> {
                        j
                    };
                }
                else if (s == min)
                {
                    mins.Add(j);
                }

                if (s > max)
                {
                    max  = s;
                    maxs = new List <int> {
                        j
                    };
                }
                else if (s == max)
                {
                    maxs.Add(j);
                }

                sum += s;
            }

            var m = 0;

            foreach (var i in maxs)
            {
                foreach (var table in combinations[i])
                {
                    var sympathy = Table.GetSympathy(table[0], table[1]);

                    if (sympathy > m)
                    {
                        m = sympathy;
                    }
                }
            }

            foreach (var boy in boys)
            {
                foreach (var girl in girls)
                {
                    if (IsComplex(boy, girl, boys, girls, m, max, sympathies))
                    {
                        complexity++;
                    }
                }
            }

            worst = combinations[mins[CRandom.GetRandom(0, mins.Count)]];
            best  = combinations[maxs[CRandom.GetRandom(0, maxs.Count)]];

            stopWatch.Stop();

            Debug.Log(string.Format("min={0}, max={1}, avg={2}, minRate={3}, maxRate={4}, m={5} complexity={6}", min, max, (float)sum / combinations.Count, mins.Count, maxs.Count, m, complexity));
            Debug.Log("Analize: stopWatch.Elapsed=" + stopWatch.Elapsed.TotalSeconds);
        }
Ejemplo n.º 30
0
        public BalanceGA(PopulationManager <BalanceGA> Manager, List <double> root = null, CRandom rand = null)
        {
            UpdatedAtGeneration = -1;

            if (rand != null)
            {
                this.rand = new CRandom(rand.Next());
            }

            ReloadParameters(Manager);

            Vector = root;

            //Generate random one
            if (root == null)
            {
                Vector    = GenerateData();
                CreatedBy = "Random";
            }

            this.CreatedAtGeneration = Manager.GenerationsRun + 1;
        }