public override void takeTurn() { RecordHistory.current.record(); AForge.Genetic.Population ga = new AForge.Genetic.Population(popSize, new AForge.Genetic.ShortArrayChromosome(depth), fit, new AForge.Genetic.RankSelection(), random); bool tempRecord = GameController.recording; GameController.recording = false; int i = 0; while (fit.timesEvaluated < evaluations) { //Getting an index out of range exception here when using RouletteWheelSelection (16 rounds in, seed 100) ga.RunEpoch(); RecordHistory.current.plot(i + "," + ga.FitnessMax + Environment.NewLine); if ((GameController.turn % 5 == 0) && (i == 0 || i == generations / 2 || i == generations - 1)) { List<double> fitnesses = ga.getFitnesses(); List<double> parents = ga.getParentFitnesses(); List<string> snap = new List<string>(); for (int j = 0; j < fitnesses.Count; j++) snap.Add(fitnesses[j].ToString() + "," + parents[j].ToString()); RecordHistory.current.snapshot(snap); } i++; } lastBestChromosome = ga.BestChromosome as AForge.Genetic.ShortArrayChromosome; fit.timesEvaluated = 0; GameController.recording = tempRecord; fit.Evaluate(lastBestChromosome); Move m = Board.current.legalMoves[lastBestChromosome.Value[0] % Board.current.legalMoves.Count]; takeAction(m); RecordHistory.current.record(this + " took move " + m); }
public override void takeTurn() { RecordHistory.current.record(); AForge.Genetic.Population ga = new AForge.Genetic.Population(popSize, new ExactChromosome(depth), fit, new AForge.Genetic.RankSelection(), random); bool tempRecord = GameController.recording; GameController.recording = false; int i = 0; while (fit.timesEvaluated < evaluations) { //Getting an index out of range exception here when using RouletteWheelSelection (16 rounds in, seed 100) ga.RunEpoch(); RecordHistory.current.plot(i + "," + ga.FitnessMax + Environment.NewLine); if ((GameController.turn % 5 == 0) && (i == 0 || i == generations / 2 || i == generations - 1)) { List<double> fitnesses = ga.getFitnesses(); List<double> parents = ga.getParentFitnesses(); List<string> snap = new List<string>(); for (int j = 0; j < fitnesses.Count; j++) snap.Add(fitnesses[j].ToString() + "," + parents[j].ToString()); RecordHistory.current.snapshot(snap); } i++; } lastBestChromosome = ga.BestChromosome as ExactChromosome; fit.timesEvaluated = 0; GameController.recording = tempRecord; fit.Evaluate(lastBestChromosome); Move m = lastBestChromosome.moves[0]; if (m == null) { m = Move.getRandomMove(); throw new NullReferenceException("ExactGene couldn't find a random move."); } CONSOLE.Overwrite(12, "Illegals: " + fit.Illegals); CONSOLE.Overwrite(13, "Moves: " + fit.MovesTaken); takeAction(m); RecordHistory.current.record(this + " took move " + m); }