The following piece of code makes sure that each mutation is done both as a decrement and an increment.
mutation *= -1; // Alternate between incrementing and decrementing. if (mutation == 1) // After gene has been both incremented and decremented, move to next one. { mutatedGene = (mutatedGene + 1) % Biomorph.GENE_COUNT; }
But if the 'Biomorph.GENE_COUNT' is 8 then the 9 Biomorphs will mutate genes 0, 1, -1, 2, -2, 3, -3, and 4. It will never mutate genes -4, 5, -5, 6, -6, or 7.
The following piece of code makes sure that each mutation is done both as a decrement and an increment.
mutation *= -1; // Alternate between incrementing and decrementing. if (mutation == 1) // After gene has been both incremented and decremented, move to next one. { mutatedGene = (mutatedGene + 1) % Biomorph.GENE_COUNT; }But if the 'Biomorph.GENE_COUNT' is 8 then the 9 Biomorphs will mutate genes 0, 1, -1, 2, -2, 3, -3, and 4. It will never mutate genes -4, 5, -5, 6, -6, or 7.