Beispiel #1
0
 static void displayInfo()
 {
     Console.WriteLine(new String('\n', Console.WindowHeight - 9) +
                       "Best Fitness: " + best.fitness + "\n" +
                       "Best phrase: " + CharGenome.getGenomeValue(best) + "\n" +
                       "Total generations: " + generation + "\n" +
                       "Average fitness: " + avgFit + "\n" +
                       "total population: " + pop.pop.Length + "\n" +
                       "mutation rate: " + pop.pop[0].genome.mutationRate + "\n" +
                       "slows: " + pop.genome.slowDownTop + "\n" +
                       "clones: " + pop.genome.clonesToKeep + "\n" +
                       "Command: ");
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Make buffer not store history so no clear is needed.
            Console.BufferHeight = Console.WindowHeight;

            bool updated = true;

            setup();
            while (running)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    switch (key.Key)
                    {
                    case ConsoleKey.Q:
                        running = false;
                        updated = true;
                        break;

                    case ConsoleKey.Insert:
                        if (key.Modifiers == ConsoleModifiers.Shift)
                        {
                            pop.genome.mutationRate += 0.001f;
                        }
                        else
                        {
                            pop.genome.mutationRate += 0.01f;
                        }
                        updated = true;
                        break;

                    case ConsoleKey.Delete:
                        if (key.Modifiers == ConsoleModifiers.Shift)
                        {
                            pop.genome.mutationRate -= 0.001f;
                        }
                        else
                        {
                            pop.genome.mutationRate -= 0.01f;
                        }
                        updated = true;
                        break;

                    case ConsoleKey.Home:
                        pop.genome.slowDownTop++;
                        pop.calcFitness();
                        updated = true;
                        break;

                    case ConsoleKey.End:
                        pop.genome.slowDownTop--;
                        updated = true;
                        break;

                    case ConsoleKey.PageUp:
                        pop.genome.clonesToKeep++;
                        pop.calcFitness();
                        updated = true;
                        break;

                    case ConsoleKey.PageDown:
                        pop.genome.clonesToKeep--;
                        updated = true;
                        break;

                    default:
                        break;
                    }
                }
                update();
                updateStats();
                if (generation % 25 == 0 || updated)
                {
                    displayInfo();
                    updated = false;
                }
                if (CharGenome.getGenomeValue(best) == target)
                {
                    running = false;
                }
            }
            Console.WriteLine("\nDone... Press any key to exit...");
            Console.ReadKey();
        }