Original Post
I'm interested in writing a genetic algorithm. I'm sure my idea for it is nothing new or breathtaking, but I'd like to imlement it as follows: There is a world grid of arbitrary size. Food is present distributed more or less randomly. The creatures are placed randomly at the start. They wander around eating food and their fitness will be how many foodstuffs they ate. At the end I'll create a new population of the same size by iterating over the population n times and allowing them to reproduce with a likelihood in proportion to their fitness. I'll have some mutation and crossover. Simple and elementary. Now for my problem.. and I'm sure this is probably the hardest part to figure out for any GA. How will the genetic information work for individuals. More details: The creature can make one of four choices, to move up, down, left, or right. Moving onto a food eats it and causes another food to spawn in a random location (not ontop of a creature or another food) and two creatures can't occupy the same spot, though a creature could elect that his move will be onto a square that another creature occupies. Assuming that the second creature moves away for his move, then the first creature will be able to move there, otherwies he will sit still. The creatures have their genetic code AND are able to see everything in a 5 by 5 grid centered around themself. The world wraps top to bottom and left to right and if they are at an edge, their field of vision is still 5x5 and just wraps around the world to the other side. The problem at last: How do I make some genetic code that can operate on this 5x5 bit of data to yield a result in which direction to choose? I thought at first of having four 5x5 matrices and just multiplying the vision state matrix with each of thoes fuor (one for each direction) and having the creature choose a direction based on which product was largest or smallest or closest to some value. But I realize that with the world being random and there being nothing special about up, down, left, or right from one world to the next, this would not accomplish anything. What I want is for there to be some genetic information that the creature can use to help it decide a direction to take based on it's current 5x5 vision matrix. I'm hoping to see little patterns evolve.. like here are some examples i envision: -creature sees 2 foods to it's lower right, but another creature is in between it and th food. it sees 1 food to it's upper left... and it goes for the food in the upper left.. because evolution wise, those that went for that.. would be more likely to get to get any food at all.. but if there were no creature present.. it would go for the 2 foodstuffs instead of the 1.. or maybe.. if there were 3 or 4 foodstuffs, with another creature in between, and 1 in the upper left, it would go for the 3 or 4, knowing that even though it won't get there first, it would still be more likely to get at least 1 or maybe 2 than if it went for the lone foodstuff well that basically encapsulated the majority of my hopes for the creatures. i realize that this type of behavior is very complex and would probably involve making the genetic code very very long and require hundreds or thousands or millions of generations to evolve.. but i don't care about that. i just want to know how to code some dna that could somehow operate on the 5x5 vision matrix to produce behavior relevant to the current vision state. just this moment i've had a slight idea.. that is probably trash. but maybe.. a vector for each of the 24 non-center squares in the 5x5 vision matrix.. weighted by what it is pointing to.. a foodstuff, an empty square, or an enemy, and by the contents of the few squares near what it's pointing to.. then summing all the vectors up to get a resultant direction.. maybe that's not such a trashy idea after all.. in fact maybe that's a perverse and gross and grossly oversimplified analogue to the way real brains make decisions.. i don't know.. if anyone has a better idea.. or has knowledge of this type of thing and can point me in the right direction, i would appreciate it. thanks. edit: now that i think about it.. my comment about what i figured is probably the hardest part for any GA was probably wrong. i bet it's the fitness function, but since that's so simple in this problem.. i'm just refering to what's the most difficult for this problem.