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)); } }
public ZeldaGenome(ZeldaConfiguration configuration) { this.configuration = configuration; // add some more genes int count = configuration.CalcNumInitialGenes(); this.genes = GeneUtils.Generate(count, factory, configuration); }
/// 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); }
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); }
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); }
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); }
public ToolGene(ZeldaConfiguration configuration) : base(configuration) { this.toolType = configuration.RandomToolType(); this.toolLocation = configuration.RandomLocation(); }
public OneWayGene(ZeldaConfiguration configuration) : base(configuration) { this.wayStart = RandomLocation(); this.wayEnd = RandomLocation(wayStart); }
public ColorSwitchGene(ZeldaConfiguration configuration) : base(configuration) { this.switchType = configuration.RandomSwitchType(); this.switchLocation = RandomLocation(); }
public ZeldaGenomeFactory(ZeldaConfiguration configuration) { this.configuration = configuration; }
public ZeldaGene(ZeldaConfiguration configuration) { this.configuration = configuration; }
private ZeldaGenome(ZeldaConfiguration configuration, List <ZeldaGene> genes) { this.configuration = configuration; this.genes = genes; }