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())); }
public static List <NeuroEvolveBot> GetBots(NetworkType networkType, IRandomNumberGenerator <double> rand) { var values = FileHandler.GetGenerations(networkType); List <NeuroEvolveBot> bots = new List <NeuroEvolveBot>(); for (int i = 0; i < values.Count; i++) { var chrome = new DoubleArrayChromosome(rand, rand, rand, values[i]); var net = GetNetHelper.GetNet(chrome, new int[] { 5, 4, 3 }); var bot = new NeuroEvolveBot(net, i, "NeuroEvolve" + " " + i); bots.Add(bot); } return(bots); }
public double Evaluate(IChromosome chromosone) { double score = 0; var net = GetNetHelper.GetNet(chromosone, new int[] { 5, 4, 3 }); var GameRunner = new GameRunnerWithData(); foreach (var bot in bots) { var data = GameRunner.RunGame(bot, new NeuroEvolveBot(net, rand.Next(1, 256))); score += GeneralScore(data.P2WinCount, data.P1WinCount, data); } double scaling = (double)bots.Count(); score = Math.Max(score + 1, 0.01) / scaling; return(Math.Exp(score * 3)); }
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(); }