Example #1
0
        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);
            }
        }
Example #2
0
        internal SubstractPolygonMutationChanges RemovePolygonAtPosition(int position)
        {
            if (this.Polygons.Count > 0)
            {
                SubstractPolygonMutationChanges changes = new SubstractPolygonMutationChanges();
                changes.OldNegativeFitness = this.NegativeFitness;

                Point[] polygon = this.Polygons[position];
                Brush   brush   = this.Brushes[position];

                changes.Index      = position;
                changes.OldPolygon = polygon;
                changes.OldBrush   = brush;

                this.Polygons.RemoveAt(position);
                this.Brushes.RemoveAt(position);

                this.NegativeFitness       = computeNegativeFittness();
                changes.NewNegativeFitness = this.NegativeFitness;
                return(changes);
            }
            return(null);
        }