예제 #1
0
        public static void Mutate <T>(List <T> genes, GeneFactory <T> geneFactory, ZeldaConfiguration configuration) where T : Gene
        {
            // delete some genes
            int numDeletions = configuration.CalcNumDeletions(genes.Count);

            genes.Shuffle(configuration.Random);
            genes.RemoveRange(genes.Count - numDeletions, numDeletions);

            // mutate some genes
            int numMutations = configuration.CalcNumMutations(genes.Count);

            for (int i = 0; i < numMutations; i++)
            {
                var original = genes[i];
                var mutation = original.Mutate();
                genes[i] = (T)mutation;
            }

            // insert some genes
            int numInsertions = configuration.CalcNumInsertions(genes.Count);

            for (int i = 0; i < numInsertions; i++)
            {
                genes.Add(geneFactory.CreateGene(configuration));
            }
        }
예제 #2
0
        public ZeldaGenome(ZeldaConfiguration configuration)
        {
            this.configuration = configuration;

            // add some more genes
            int count = configuration.CalcNumInitialGenes();

            this.genes = GeneUtils.Generate(count, factory, configuration);
        }
예제 #3
0
        /// generate some genes
        public static List <T> Generate <T>(int count, GeneFactory <T> factory, ZeldaConfiguration configuration) where T : Gene
        {
            var result = new List <T>();

            for (int i = 0; i < count; i++)
            {
                result.Add(factory.CreateGene(configuration));
            }
            return(result);
        }
예제 #4
0
        public KeyDoorGene(ZeldaConfiguration configuration)
            : base(configuration)
        {
            this.keyType     = configuration.RandomKeyType();
            this.keyLocation = RandomLocation();
            int a = RandomLocation();
            int b = RandomLocation(a);

            this.doorStart = Math.Min(a, b);
            this.doorEnd   = Math.Max(a, b);
        }
예제 #5
0
        public ColorPistonGene(ZeldaConfiguration configuration)
            : base(configuration)
        {
            this.switchType  = configuration.RandomSwitchType();
            this.switchColor = configuration.RandomSwitchColor();

            int a = RandomLocation();
            int b = RandomLocation(a);

            this.pistonStart = Math.Min(a, b);
            this.pistonEnd   = Math.Max(a, b);
        }
예제 #6
0
        public ZeldaGene CreateGene(ZeldaConfiguration configuration)
        {
            switch (configuration.RandomGeneType())
            {
            case 0: return(new ColorPistonGene(configuration));

            case 1: return(new ColorSwitchGene(configuration));

            case 2: return(new KeyDoorGene(configuration));

            case 3: return(new ObstacleGene(configuration));

            case 4: return(new OneWayGene(configuration));

            case 5: return(new ToolGene(configuration));
            }

            Debug.Fail();
            return(null);
        }
예제 #7
0
 public ToolGene(ZeldaConfiguration configuration)
     : base(configuration)
 {
     this.toolType     = configuration.RandomToolType();
     this.toolLocation = configuration.RandomLocation();
 }
예제 #8
0
 public OneWayGene(ZeldaConfiguration configuration)
     : base(configuration)
 {
     this.wayStart = RandomLocation();
     this.wayEnd   = RandomLocation(wayStart);
 }
예제 #9
0
 public ColorSwitchGene(ZeldaConfiguration configuration)
     : base(configuration)
 {
     this.switchType     = configuration.RandomSwitchType();
     this.switchLocation = RandomLocation();
 }
예제 #10
0
 public ZeldaGenomeFactory(ZeldaConfiguration configuration)
 {
     this.configuration = configuration;
 }
예제 #11
0
 public ZeldaGene(ZeldaConfiguration configuration)
 {
     this.configuration = configuration;
 }
예제 #12
0
 private ZeldaGenome(ZeldaConfiguration configuration, List <ZeldaGene> genes)
 {
     this.configuration = configuration;
     this.genes         = genes;
 }