Ejemplo n.º 1
0
        protected override void Restart()
        {
            if (Birds != null)
            {
                var maxScore = Birds.Select(bird => bird.Score).Max();
                if (maxScore >= 100)
                {
                    var primeBird = Birds.First(bird => bird.Score == maxScore);
                    var weights   = aiTrainingFramework.CurrentGenWeights[primeBird.Id];
                    JsonFileWriter.SerializeWeights(weights, @"D:\VS Projects\MachineLearningGames\flappyBirdWeights.json");
                    Environment.Exit(0);
                }

                var scores = Birds.Select(bird => (bird.Id, (bird.Score + 1) * aliveTime[bird.Id])).ToList();
                Controllers = aiTrainingFramework.CreateNewControllers(scores);
            }

            aliveTime = Controllers.ToDictionary(c => c.Id, c => 0);

            base.Restart();
        }