Created
October 5, 2013 10:03
-
-
Save chopmann/6839050 to your computer and use it in GitHub Desktop.
Genen und Mutationen Pseudo Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
genes = new int[8]; | |
Random rand = new Random(); | |
for (int i = 0; i < genes.length; i++) { | |
genes[i] = Helper.randInt(1, 10, rand); | |
} | |
/** http://stackoverflow.com/questions/363681/generating-random-numbers-in-a-range-with-java */ | |
public static int randInt(int min, int max, Random rand) { | |
// nextInt is normally exclusive of the top value, | |
// so add 1 to make it inclusive | |
int randomNum = rand.nextInt((max - min) + 1) + min; | |
return randomNum; | |
} | |
// Die Mutation | |
Du nimmst den Array von der MamaTier | |
int [] mamaGene = Mama.getGene() | |
Danach machst du ein clone davon: | |
int [] kindGene ) = mamaGene.clone() | |
Danach wird Zufällig im Interval 0-7 ein Gen um Zufällig +1 oder -1 oder 0 verändert. | |
Dh. | |
int randomGene = randInt(0, 7, Random rand) | |
kindGene[randomGene] += randInt(-1, 1, Random rand) | |
Jetzt haben wir die Genen Mutiert und die Müssen wieder zurück | |
Kind.setGene( kindGene) | |
So habe ich es verstanden. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment