private Biomorph mutateBiomorph ( Biomorph biomorph , Random rng ) { int [ ] genes = biomorph . getGenotype ( ) ; assert genes . length == Biomorph . GENE_COUNT : "Biomorphs must have " + Biomorph . GENE_COUNT + " genes." ; for ( int i = 0 ; i < Biomorph . GENE_COUNT - 1 ; i ++ ) { if ( mutationProbability . nextEvent ( rng ) ) { boolean increase = rng . nextBoolean ( ) ; genes [ i ] += ( increase ? 1 : - 1 ) ; if ( genes [ i ] > Biomorph . GENE_MAX ) { genes [ i ] = Biomorph . GENE_MIN ; } else if ( genes [ i ] < Biomorph . GENE_MIN ) { genes [ i ] = Biomorph . GENE_MAX ; } } } boolean increase = rng . nextBoolean ( ) ; genes [ Biomorph . LENGTH_GENE_INDEX ] += ( increase ? 1 : - 1 ) ; if ( genes [ Biomorph . LENGTH_GENE_INDEX ] > Biomorph . LENGTH_GENE_MAX ) { genes [ Biomorph . LENGTH_GENE_INDEX ] = Biomorph . LENGTH_GENE_MIN ; } else if ( genes [ Biomorph . LENGTH_GENE_INDEX ] < Biomorph . LENGTH_GENE_MIN ) { genes [ Biomorph . LENGTH_GENE_INDEX ] = Biomorph . LENGTH_GENE_MAX ; } return new Biomorph ( genes ) ; }
Mutates a single biomorph .