Пример #1
0
    IEnumerator DoPreform()
    {
        var logs = new LocoLogs();

        _monsPerRound     = 40;
        _monsToKeep       = 6;
        _childrenToMutate = 6;
        _bestInject       = 1;

        Application.RegisterLogCallback(OnLog);

        List <Locomotion> bestLocos = new List <Locomotion>();

        while (true)
        {
            LoadConfigSettings();

            Generation++;
            var locos = new List <Locomotion>();

            var i = 0;
            for (var bestIndex = 0; bestIndex < bestLocos.Count; ++bestIndex)
            {
                if (_bestInject > 0 &&
                    bestIndex >= _monsToKeep - _bestInject && _bestAllTime != null)
                {
                    //Use best alltime
                    for (var childIndex = 0; childIndex < _childrenToMutate; ++childIndex)
                    {
                        locos.Add(new Locomotion(_monsPerRound - i - 1, _bestAllTime));
                        i++;
                    }
                    continue;
                }

                for (var childIndex = 0; childIndex < _childrenToMutate; ++childIndex)
                {
                    //Index modified so children appear at front
                    locos.Add(new Locomotion(_monsPerRound - i - 1, bestLocos[bestIndex]));
                    i++;
                }
            }

            for (; i < _monsPerRound; i++)
            {
                //Index modified so children appear at front
                locos.Add(new Locomotion(_monsPerRound - i - 1, null));
            }

            while (locos.Any(l => !l.Finished))
            {
                yield return(null);
            }

            foreach (var loco in locos)
            {
                logs.Save(loco);
            }


            bestLocos = locos.OrderByDescending(loco => loco.FinalScore).Take(_monsToKeep).ToList();

            var best = bestLocos.First();
            if (_bestAllTime == null || best.FinalScore > _bestAllTime.FinalScore)
            {
                _bestAllTime = best;
            }

            if (bestLocos.First().FinalScore > TopScore)
            {
                TopScore    = bestLocos.First().FinalScore;
                TopScoreGen = Generation;
            }

            foreach (var l in locos)
            {
                l.Stop();
            }
        }
    }
Пример #2
0
    IEnumerator DoPreform()
    {
        var logs = new LocoLogs();
        _monsPerRound = 40;
        _monsToKeep = 6;
        _childrenToMutate = 6;
        _bestInject = 1;

        Application.RegisterLogCallback(OnLog);

        List<Locomotion> bestLocos = new List<Locomotion>();
        while(true)
        {
            LoadConfigSettings();

            Generation++;
            var locos = new List<Locomotion>();

            var i = 0;
            for (var bestIndex = 0; bestIndex < bestLocos.Count; ++bestIndex )
            {
                if (_bestInject > 0
                    && bestIndex >= _monsToKeep - _bestInject && _bestAllTime != null)
                {
                    //Use best alltime
                    for (var childIndex = 0; childIndex < _childrenToMutate; ++childIndex)
                    {
                        locos.Add(new Locomotion(_monsPerRound - i - 1, _bestAllTime));
                        i++;
                    }
                    continue;
                }

                for (var childIndex = 0; childIndex < _childrenToMutate; ++childIndex)
                {
                    //Index modified so children appear at front
                    locos.Add(new Locomotion(_monsPerRound - i - 1, bestLocos[bestIndex]));
                    i++;
                }
            }

            for (; i < _monsPerRound; i++)
            {
                //Index modified so children appear at front
                locos.Add(new Locomotion(_monsPerRound - i - 1, null));
            }

            while (locos.Any(l => !l.Finished))
                yield return null;

            foreach (var loco in locos)
                logs.Save(loco);

            bestLocos = locos.OrderByDescending(loco => loco.FinalScore).Take(_monsToKeep).ToList();

            var best = bestLocos.First();
            if (_bestAllTime == null || best.FinalScore > _bestAllTime.FinalScore)
                _bestAllTime = best;

            if (bestLocos.First().FinalScore > TopScore)
            {
                TopScore = bestLocos.First().FinalScore;
                TopScoreGen = Generation;
            }

            foreach (var l in locos)
                l.Stop();
        }
    }