private Generation CreateGenerationOfMutants(List <string> baseGenomes)
    {
        //Debug.Log("Generating generation from [" + string.Join(",", baseGenomes.ToArray()) + "]");
        var genration = new Generation();
        int i         = 0;

        //Debug.Log("IndinvidualsCount = " + genration.CountIndividuals());
        while (genration.CountIndividuals() < GenerationSize)
        {
            var baseGenome = baseGenomes[i];
            var mutant     = _mutator.Mutate(baseGenome);
            if (IsValidGenome(mutant))
            {
                Debug.Log(mutant + " spawn of " + baseGenome + " is born");
                genration.AddGenome(mutant);
                //Debug.Log("IndinvidualsCount = " + genration.CountIndividuals());
            }
            else
            {
                Debug.Log(mutant + " spawn of " + baseGenome + " is too rubbish to be born");
            }
            i++;
            i = i % baseGenomes.Count;
        }
        //Debug.Log("mutant Generation: " + genration);
        return(genration);
    }
    public void RecordMatch_SavesCombatants()
    {
        var gen = new Generation();
        var a   = "a";
        var b   = "b";

        gen.AddGenome(a);
        gen.AddGenome(b);
        gen.AddGenome("blancmonge");

        gen.RecordMatch(a, b, a, 13, 7, 5);

        var genString = gen.ToString();

        Assert.True(genString.Contains("a;13;1;0;0;b"), "a's line is wrong");
        Assert.True(genString.Contains("b;7;0;0;1;a"), "b's line is wrong");
    }
Exemple #3
0
        private List <float> Testpickwinnersdistribution_MoreRandom(int generationSize, int winnersCount, int runs = 1000)
        {
            Debug.Log(runs + "runs, " + generationSize + " individuals, " + winnersCount + " winners");
            var all   = new List <float>();
            var maxes = new List <float>();
            var mins  = new List <float>();

            var gen = new Generation();

            var random = new System.Random();

            for (int i = 0; i < generationSize; i++)
            {
                var score = (float)(0.5 - random.NextDouble()) * 1000;

                gen.AddGenome(score.ToString());

                gen.RecordMatch(new GenomeWrapper(score.ToString()), score, true, true, 1, null, false);
            }

            for (int j = 0; j < runs; j++)
            {
                var winners = gen.PickWinners(winnersCount);

                var ints = winners.Select(g => float.Parse(g)).ToList();

                all.AddRange(ints);
                maxes.Add(ints.Max());
                mins.Add(ints.Min());
            }
            Debug.Log("max max: " + maxes.Max() + ", min max: " + maxes.Min());
            Debug.Log("max min: " + mins.Max() + ", min min: " + mins.Min());
            Debug.Log("max all: " + all.Max() + ", min all: " + all.Min());

            //Debug.Log("all:  " + string.Join(",",  all.OrderBy(x => x).Select(x => x.ToString()).Take(30).ToArray()));
            //Debug.Log("mins: " + string.Join(",", mins.OrderBy(x => x).Select(x => x.ToString()).Take(30).ToArray()));

            var groups = all.GroupBy(i => i);

            foreach (var group in groups.OrderByDescending(g => g.Key))
            {
                Debug.Log((group.Key.ToString()).PadRight(10) +
                          (" (" + group.Count().ToString() + ")").PadRight(8) +
                          "".PadRight(group.Count() * 80 / runs, '|'));
            }

            return(all);
        }