示例#1
0
        static void Main(string[] args)
        {
            NetworkType chromType = GenTypes.ReLU;

            var prevNeuralBots = new List <NeuroEvolveBot>();
            var genValues      = FileHandler.GetGenerations(GenTypes.ReLU);
            var rand           = new ZigguratExponentialGenerator();
            var Bots           = GetBots(chromType, rand);

            prevNeuralBots.AddRange(Bots);



            /*
             *              ;
             *
             *              for (int i = 0; i < largestGen + 1; i++)
             *              {
             *                  prevNeuralBots.Add(getBotGen(i, rand, chromType));
             *              }*/


            var bots = new List <IBot> {
                new DrawBot()
            };

            bots.AddRange(prevNeuralBots);

            var bestChromeValues = FileHandler.GetGenerations(chromType);
            DoubleArrayChromosome doubleChromosome = new DoubleArrayChromosome(rand, rand, rand, bestChromeValues[bestChromeValues.Count - 1]);

            //DoubleArrayChromosome doubleChromosome = (DoubleArrayChromosome)GetChromosomeGen(largestGen, rand, chromType);

            for (int i = 0; i < 10; i++)
            {
                var pop = new Population(200, doubleChromosome, new fitFuncForAdaptable(bots), new RouletteWheelSelection());
                Console.WriteLine(pop.FitnessMax);
                for (int j = 0; j < 10; j++)
                {
                    pop.RunEpoch();
                    Console.WriteLine(pop.FitnessMax);
                    Console.WriteLine(pop.FitnessAvg);
                }

                var x = new fitFuncForAdaptable(bots).Evaluate(pop.BestChromosome);
                doubleChromosome = (DoubleArrayChromosome)pop.BestChromosome;

                var newNet = GetNetHelper.GetNet(doubleChromosome, new[] { 5, 4, 3 });
                var newBot = new NeuroEvolveBot(newNet, 934 + i, "newBot" + i.ToString());

                var      gameRunner = new GameRunnerWithData();
                GameData data;
                foreach (var bot in bots)
                {
                    data = gameRunner.RunGame(newBot, bot);
                    Console.WriteLine(data);
                }
                data = gameRunner.RunGame(newBot, new WaveBot());
                Console.WriteLine(data);
                bots.Add(newBot);
            }

            double[] values = doubleChromosome.Value;

            FileHandler.WriteToLargestGen(chromType, values);
            RunWaveTest();
        }
示例#2
0
        private static NeuroEvolveBot getBotGen(int genNumber, IRandomNumberGenerator <double> rand, NetworkType networkType)
        {
            var chromosome = (DoubleArrayChromosome)GetChromosomeGen(genNumber, rand, networkType);
            var net        = GetNetHelper.GetNet(chromosome, new int[] { 5, 4, 3 });

            return(new NeuroEvolveBot(net, genNumber, genNumber.ToString()));
        }
示例#3
0
        private static IChromosome GetChromosomeGen(int genNumber, IRandomNumberGenerator <double> rand, NetworkType networkType)
        {
            var newChromeValues = File.ReadAllLines("Chromosome" + networkType.fileName + genNumber.ToString()).Select(s => double.Parse(s)).ToArray();

            return(new DoubleArrayChromosome(rand, rand, rand, newChromeValues));
        }
示例#4
0
        private static IEnumerable <string> GetFileNames(NetworkType networkType)
        {
            var files = Directory.GetFiles(Directory.GetCurrentDirectory());//Must be a better way lol

            return(files.Where(s => s.Contains(networkType.fileName)));
        }