internal void ApplyMutation(IMutationChanges changes) { if (changes == null) { return; } this.NegativeFitness = changes.NewNegativeFitness; if (changes is PolygonAndColorMutationChanges) { PolygonAndColorMutationChanges change = (PolygonAndColorMutationChanges)changes; int index = change.Index; Point[] polygon = change.NewPolygon; Brush brush = change.NewBrush; this.Polygons[index] = polygon; this.Brushes[index] = brush; } else if (changes is ColorMutationChanges) { ColorMutationChanges change = (ColorMutationChanges)changes; int index = change.Index; Brush brush = change.NewBrush; this.Brushes[index] = brush; } else if (changes is PolygonMutationChanges) { PolygonMutationChanges change = (PolygonMutationChanges)changes; int index = change.Index; Point[] polygon = change.NewPolygon; this.Polygons[index] = polygon; } else if (changes is SubstractPolygonMutationChanges) { SubstractPolygonMutationChanges change = (SubstractPolygonMutationChanges)changes; int index = change.Index; Point[] polygon = change.OldPolygon; Brush brush = change.OldBrush; //this.Polygons.Insert(index, polygon); //this.GeneBrush.Insert(index, brush); this.Brushes.RemoveAt(index); this.Polygons.RemoveAt(index); } else if (changes is AddPolygonMutationChanges) { AddPolygonMutationChanges change = (AddPolygonMutationChanges)changes; int index = change.Index; Point[] polygon = change.NewPolygon; Brush brush = change.NewBrush; this.Brushes.Insert(index, brush); this.Polygons.Insert(index, polygon); } }
internal AddPolygonMutationChanges AddPolygon() { AddPolygonMutationChanges changes = new AddPolygonMutationChanges(); changes.OldNegativeFitness = this.NegativeFitness; int numberOfPoints = 3 + random.Next(RandSeed); Point[] polygon = getPoints(numberOfPoints); Brush brush = getRandomBrush(); changes.Index = Polygons.Count; Polygons.Add(polygon); Brushes.Add(brush); changes.NewPolygon = polygon; changes.NewBrush = brush; this.NegativeFitness = computeNegativeFittness(); changes.NewNegativeFitness = this.NegativeFitness; return(changes); }