SuperImageEvolver.DNA.SwapShapes C# (CSharp) Method

SwapShapes() public method

public SwapShapes ( Random rand ) : void
rand Random
return void
        public void SwapShapes(Random rand)
        {
            int s1 = rand.Next(Shapes.Length);
            Shape shape = Shapes[s1];
            shape.PreviousState = shape.Clone() as Shape;
            if (rand.Next(2) == 0) {
                int s2;
                do {
                    s2 = rand.Next(Shapes.Length);
                } while (s1 == s2);
                ShiftShapeIndex(s1, s2);
            } else {
                int s2 = rand.Next(Shapes.Length);
                Shapes[s1] = Shapes[s2];
                Shapes[s2] = shape;
            }
            LastMutation = MutationType.SwapShapes;
        }

Usage Example

Esempio n. 1
0
        DNA IMutator.Mutate( Random rand, DNA oldDNA, TaskState task )
        {
            DNA newDNA = new DNA( oldDNA );
            if( rand.Next( 20 ) == 0 ) {
                newDNA.SwapShapes( rand );
            } else {
                MutateShape( rand, newDNA, newDNA.Shapes[rand.Next( newDNA.Shapes.Length )], task );
            }

            return newDNA;
        }
All Usage Examples Of SuperImageEvolver.DNA::SwapShapes