/// <summary> /// Creates a copy of this GeneSequence /// </summary> /// <returns></returns> public GeneSequence Copy(double mutateChance = 0.01, double splitChance = 0.002) { GeneSequence result = new GeneSequence(Clone(Start), Random); Queue <Gene> queue = new Queue <Gene>(); queue.Enqueue(result.Start); while (queue.Count > 0) { Gene current = queue.Dequeue(); if (Random.NextDouble() < splitChance) { current.Genes.Add(Gene.Random(Random)); } foreach (Gene gene in current.Genes) { queue.Enqueue(gene); } if (Random.NextDouble() < mutateChance) { current.Value = (char)((current.Value + (Random.Next(2) == 0 ? -1 : 1) + char.MaxValue) % char.MaxValue); } } return(result); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; GeneSequence sequence = new GeneSequence('A'); for (int i = 0; i < 2; i++) { sequence.Extend((char)('B' + i)); } PetriDish dish = new PetriDish(sequence); dish.Iterate(100); //dish.PrintData(); dish.SaveData("test.txt"); }
public PetriDish(GeneSequence original) { Generations.Add(CurrentGen, original); CurrentGenHash = original.GetHashCode(); }