I've created a game (basically an Agar.io clone), where a human player is placed against AI controlled bots powered by a genetic algorithm and neural networks.
The problem is that I think that my algorithm isn't efficient. I have 10 bots ranked by their fitness function, which is time survived. Their gene consists of real numbers between -1 and 1.
From lowest to highest fitness, I take n bots up to 5 bots and take the current weight value and add it by a Gaussian number multiplied by (\$10^{-n}\$). I had trouble performing crossover with floating point numbers, thus I only did mutation like this.
Obviously, my AI isn't very intelligent.
How could I improve my algorithm?
if (generation != 1) {
for (int g = 0; g < geneRecord.size - 5; g++) {
Random randomno = new Random();
for (int y = 0; y < geneRecord.get(g).size; y++) {
float gaussian = (float) (((randomno.nextGaussian()) * Math.pow(10, -(g+1))));
if (geneRecord.get(g).get(y) + gaussian > 1) {
geneRecord.get(g).set(y, geneRecord.get(g).get(y) - gaussian);
} else {
geneRecord.get(g).set(y, geneRecord.get(g).get(y) + gaussian);
}
}
}
}
geneRecord.size
andgeneRecord.get(g).size
? Your description of your algorithm is confusing. I don't know what "I take n bots up to 5 bots" means when your loop goes from0 .. geneRecord.size - 5
. Where are the "bots"? Please explain more clearly what your code is doing. \$\endgroup\$