Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions oolab/src/main/java/agh/ics/oop/LittleAdjustment.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
package agh.ics.oop;

import java.util.Random;

public class LittleAdjustment implements IMutationModel{
@Override
public void mutate(Animal child, Animal mommy, Animal daddy) {

for (int i = 0 ; i < child.genes.length; i++){
Random generator = new Random();
int newGene = child.genes[i].toNumber();

if (generator.nextBoolean()){
newGene = (newGene + 1)%8;
}
else{
newGene = (newGene - 1)%8;
}

Direction geneToInsert = switch(newGene){
case 0 -> Direction.NORTH;
case 1 -> Direction.EASTNORTH;
case 2 -> Direction.EAST;
case 3 -> Direction.EASTSOUTH;
case 4 -> Direction.SOUTH;
case 5 -> Direction.WESTSOUTH;
case 6 -> Direction.WEST;
case 7 -> Direction.WESTNORTH;
default -> null;
};

child.genes[i] = geneToInsert;
}

}

}

22 changes: 22 additions & 0 deletions oolab/src/main/java/agh/ics/oop/TotalRandom.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
package agh.ics.oop;
import java.util.Random;

public class TotalRandom implements IMutationModel{
@Override
public void mutate(Animal child, Animal mommy, Animal daddy) {

for (int i = 0; i < child.genes.length; i++){
Random generator = new Random();

int newGene = generator.nextInt(8);

Direction geneToInsert = switch(newGene){
case 0 -> Direction.NORTH;
case 1 -> Direction.EASTNORTH;
case 2 -> Direction.EAST;
case 3 -> Direction.EASTSOUTH;
case 4 -> Direction.SOUTH;
case 5 -> Direction.WESTSOUTH;
case 6 -> Direction.WEST;
case 7 -> Direction.WESTNORTH;
default -> null;
};

child.genes[i] = geneToInsert;

}
}

}