private void Form1_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case ('w'): board.Robots[0].Move(new SizeF(0, -1)); break; case ('a'): board.Robots[0].Move(new SizeF(-1, 0)); break; case ('s'): board.Robots[0].Move(new SizeF(0, 1)); break; case ('d'): board.Robots[0].Move(new SizeF(1, 0)); break; case ('+'): FoodGatherParams.resolution *= 2; FoodGatherParams.fillFood(); if (FoodGatherParams.circle) { board.Robots[0] = new Robot(board.Robots[0].Location, (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest)); } else { board.Robots[0] = new Robot(board.Robots[0].Location, (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest)); } break; case ('-'): if (board.Robots[0].Sensors - 1 >= 1) { board.Robots[0] = new Robot(board.Robots[0].Location, board.Robots[0].Sensors - 1); } break; case ('t'): board.turn(); updateWiring(); break; case ('g'): MessageBox.Show(board.game().ToString()); break; case ('x'): board.Robots[0].Move(board.Agents[0].Location); break; case ('p'): Demo(); break; } Invalidate(Utilities.Translate(new Rectangle(new Point((int)board.Robots[0].Location.X + 2, (int)board.Robots[0].Location.Y + 2), new Size(3 * ((int)board.Robots[0].SensorRadius + 2), 3 * (int)board.Robots[0].SensorRadius + 2)))); }
private void adHocAnalysisToolStripMenuItem_Click(object sender, EventArgs e) { string filename; StreamWriter sw; NeatGenome.NeatGenome seedGenome = null; Stats currentStats = new Stats(); for (FoodGatherParams.resolution = 8; FoodGatherParams.resolution <= 128; FoodGatherParams.resolution *= 2) { FoodGatherParams.fillFood(); FoodGatherParams.fillLookups(); sw = new StreamWriter("logfile" + FoodGatherParams.resolution.ToString() + ".txt"); for (int run = 1; run <= 20; run++) { for (int generation = 1; generation <= 500; generation++) { filename = "run" + run.ToString() + @"\genome_" + generation.ToString() + ".xml"; try { XmlDocument doc = new XmlDocument(); doc.Load("run" + run.ToString() + "\\genome_" + generation.ToString() + ".xml"); seedGenome = XmlNeatGenomeReaderStatic.Read(doc); } catch (Exception ex) { //MessageBox.Show(generation.ToString()); currentStats.generation = generation; currentStats.run = run; writeStats(sw, currentStats); continue; //do some output } currentStats = FoodGathererNetworkEvaluator.postHocAnalyzer(seedGenome); currentStats.CPPNconnections = seedGenome.ConnectionGeneList.Count; currentStats.CPPNneurons = seedGenome.NeuronGeneList.Count; currentStats.generation = generation; currentStats.run = run; writeStats(sw, currentStats); //break; } // sw.Flush(); } sw.Close(); } }
public override void EvaluatePopulation(Population pop, EvolutionAlgorithm ea) { // Evaluate in single-file each genome within the population. // Only evaluate new genomes (those with EvaluationCount==0). FoodGatherParams.fillLookups(); FoodGatherParams.fillFood(); int count = pop.GenomeList.Count; for (int i = 0; i < count; i++) { IGenome g = pop.GenomeList[i]; if (g.EvaluationCount != 0) { continue; } INetwork network = g.Decode(activationFn); if (network == null) { // Future genomes may not decode - handle the possibility. g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS; } else { g.Fitness = Math.Max(networkEvaluator.EvaluateNetwork(network), EvolutionAlgorithm.MIN_GENOME_FITNESS); g.ObjectiveFitness = g.Fitness; } // Reset these genome level statistics. g.TotalFitness = g.Fitness; g.EvaluationCount = 1; // Update master evaluation counter. evaluationCount++; } if (requestResolutionUp == true) { requestResolutionUp = false; requestResolutionDown = false; FoodGatherParams.resolution *= 2; } else if (requestResolutionDown == true) { requestResolutionUp = false; requestResolutionDown = false; if (FoodGatherParams.resolution > 4) { FoodGatherParams.resolution /= 2; } } }
private void Demo() { FoodGatherParams.fillLookups(); FoodGatherParams.fillFood(); for (int j = 0; j < FoodGatherParams.foodLocations.Length; j++) { Robot r; board = new Board(0, 500); if (FoodGatherParams.circle) { r = new Robot(new PointF(250, 250), (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest)); } else { r = new Robot(new PointF(250, 250), (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest)); } board.AddRobot(r); board.AddFood(new Food(FoodGatherParams.foodLocations[j])); board.gameView(this); } }