Beispiel #1
0
 private void Start()
 {
     easyRandom = new EasyRandom();
     easyRandom.GetRandomBool(0.75f);
     easyRandom.GetRandomInt(3, 10);
     easyRandom.GetRandomFloat(0.5f, 0.1f);
     easyRandom.GetRandomVector3(0.5f, 0.1f);
     easyRandom.GetRandomVector2(0.5f, 0.1f);
     easyRandom.GetRandomSign(0.4f);
     easyRandom.GetRandomBoolTrueEnsured(3, 10);
     easyRandom.GetPseudoRandomDistributedBool(5, 0.25f);
 }
Beispiel #2
0
    public DNA GetMutation()
    {
        EasyRandom rnd = new EasyRandom();

        float mutationMutationPercentage = rnd.GetRandomFloat(1 - mutationPercentage, 1 + mutationPercentage) * mutationPercentage;
        float mutatedSpeed                 = rnd.GetRandomFloat(1 - mutationPercentage, 1 + mutationPercentage) * speed;
        float mutatedSense                 = rnd.GetRandomFloat(1 - mutationPercentage, 1 + mutationPercentage) * sense;
        float mutatedSenseFrequency        = rnd.GetRandomFloat(1 - mutationPercentage, 1 + mutationPercentage) * senseFrequency;
        float mutatedPercEnergyToReproduce = rnd.GetRandomFloat(1 - mutationPercentage, 1 + mutationPercentage) * percEnergyToReproduce;
        float mutatedMinEnergyToReproduce  = rnd.GetRandomFloat(1 - mutationPercentage, 1 + mutationPercentage) * minEnergyToReproduce;

        DNA newDna = ScriptableObject.CreateInstance <DNA>();

        newDna.SetValues(mutationMutationPercentage, mutatedSpeed, mutatedSense, mutatedSenseFrequency, mutatedPercEnergyToReproduce, mutatedMinEnergyToReproduce);
        return(newDna);
    }
Beispiel #3
0
    void Update()
    {
        // Random bool
        if (Input.GetKey(keyRandomBool))
        {
            bool obtainedBool = easyRandom.GetRandomBool(0.5f);
            if (obtainedBool)
            {
                trueBooleans++;
            }
            else
            {
                falseBooleans++;
            }
            Debug.Log("The gotten value is " + obtainedBool + ". Average = " + (trueBooleans * 100f / (trueBooleans + falseBooleans)) + "%");
        }


        // Random float
        if (Input.GetKey(keyRandomFloat))
        {
            Debug.Log("The gotten value is " + easyRandom.GetRandomFloat(3.5f, 5.0f));
        }


        // Pseudo-random distribution example (and testing)
        // An image of how the results should distribute (in blue): https://gamepedia.cursecdn.com/dota2_gamepedia/8/8b/AttacksUntilNextProc25.jpg?version=459537150af02c929fd939495fa78033
        if (Input.GetKey(keyPseudoRandom))
        {
            // You can use this code to better understand what is the result of each "RandomBool" method
            bool result = easyRandom.GetPseudoRandomDistributedBool(tryNumberSinceLastPositive, 0.25f);
            //bool result = random.GetPseudoRandomBool(tryNumber, 15);
            //bool result = random.GetRandomBool(0.2f);

            randomResults.Add(result);

            if (result)
            {
                workingTryNumbers.Add(tryNumberSinceLastPositive);
                if (tryNumberSinceLastPositive > maxTryNumber)
                {
                    maxTryNumber = tryNumberSinceLastPositive;
                }
                tryNumberSinceLastPositive = 0;
            }
            else
            {
                tryNumberSinceLastPositive++;
            }

            int[] stats = new int[maxTryNumber];
            foreach (int regTry in workingTryNumbers)
            {
                stats[regTry - 1]++;
            }

            int contador = 0;
            foreach (bool r in randomResults)
            {
                if (r)
                {
                    contador++;
                }
            }

            Debug.Log("Percentage of positive values: " + (float)contador / (float)randomResults.Count + ". Try with the maximum value: " + maxTryNumber + ". Average needed quantity of tries:" + (workingTryNumbers.Count > 0 ? workingTryNumbers.Average() : 0.0));
            DebugPro.LogEnumerable(stats, ", ", "STATS: ");
        }
    }