public DemoPlayerInputStrategy()
    {
        var population = new Population (6, 6, new DemoPlayerChromosome ());
        var fitness = new DemoPlayerFitness ();
        var selection = new EliteSelection ();
        var crossover = new OnePointCrossover (0);
        var mutation = new UniformMutation (true);

        m_ga = new GeneticAlgorithm (
            population,
            fitness,
            selection,
            crossover,
            mutation);

        m_ga.MutationProbability = 0.5f;
        m_ga.GenerationRan += (sender, e) => {
            m_bestChromossome = m_ga.BestChromosome as DemoPlayerChromosome;

            if(m_bestChromossome.AvoidAliensProjectilesProbability > 0.9f) {
                HorizontalDirection = 1f;
            }
        };
        m_ga.Start ();

        SHThread.PingPong (.01f, 0, 1, (t) => {
            m_ga.Termination = new GenerationNumberTermination (m_ga.GenerationsNumber + 1);
            m_ga.Resume();

            return true;
        });
    }
Beispiel #2
0
 public void OnePointCrossoverTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 2, 1 });
     OnePointCrossover<int> cross = new OnePointCrossover<int>(2);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 2, 1 }), new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 3, 4 }) };
     CollectionAssert.AreEqual(res, exp);
 }