예제 #1
0
        private void FullRun()
        {
            RobbyWorld world = new RobbyWorld(10, 10, 0.5f);

            IList <Reaction> rules = world.GenerateRandomRules();

            int score = world.FullRun(200, rules);

            Debug.Log(world.Log);
            Debug.Log($"Final score = {score}");
        }
예제 #2
0
        private void Optimize()
        {
            System.Random random = new System.Random();
            RobbyWorld    world  = new RobbyWorld(10, 10, 0.5f);

            GeneticAlgorithm <Reaction> ga = new GeneticAlgorithm <Reaction>(
                200,
                0.9f,
                0.1f,
                () => new Ind <Reaction>(world.GenerateRandomRules()),
                (new TournamentSelection <Reaction>(random)).Select,
                (new OnePointCrossover <Reaction>(random)).Mate,
                (new FlipEnumMutation <Reaction>(0.1f)).Mutate,
                (ind) => { world.Reset(); ind.Fit = world.FullRun(200, ind.GenesView); },
                random);

            ga.Init();

            Ind <Reaction> best = ga.Run(1000, float.PositiveInfinity);

            Debug.Log($"Best fitness is {best.Fit}");
        }