Post by ~Memzak~ on Jul 20, 2011 16:59:15 GMT
A friend of mine recently (yesterday) showed me a basic program he wrote in c++ to simulate evolution. It's very basic at the moment but now I am excited about it so I am giving him ideas and things to add to it to make it better.
So here is what it does:
It generates a "petri dish" for testing, with a food supply on every block. (40 x 40 pixels wide) It then randomly places 20 "bots" which have a basic brain with virtual neurons. (More on that later) If a bot is on a grid space it eats food. If it doesn't get food for a long enough time it dies. If it stays alive long enough it reproduces. (Into another bot of the same color and exact same brain) Food slowly regenerates but not fast enough for all 20 bots to survive, usually only 4 - 5 are left. (Ones with superior "brains") There is also a chance that a new completely random bot spawns into the petri dish.
Now here is how each bots' brain works.
In a bot's brain, there are 20 "neurons" in total. At the moment these neurons are connected directly to input and output. (This shall be improved later)
When a neuron in this brain is generated, it has a random number of inputs. (4 inputs total) One input is how much food is underneath it, the other is the red color of a bot 50 pixels in front of him. (So if a bot is too far he won't "see him") and the last two are for the blue and the green color value of a bot that is close enough to see. All inputs are converted to a number between 0 and . What then happens is that this input gets multiplied by a weight (of a randomised decimal value) and then goes to the neuron. Each Neuron has it's own unique "overflow" point. If the input multiplied by the weight is above this point, the neuron fires an output signal. If the input multiplied by the weight is lower than the overflow point then the neuron stores the value and waits for the next input. (and then adds it to the stored input and if above the overflow point it'd output and if not it would store it like before) There is a choice of random 2 outputs that a neuron can signal too. "Left Leg" and "Right Leg". It can be connected to right, left or both. If both receive a signal then the bot moves forward, if only one leg receives a signal then it would only move forward with that leg. (Turning the Bot)
This is done with 20 neurons each within each bot. (400 in the whole simulation) The best patterns in which they run around in is then the best "brain" and it survives the longest and eventually reproduces.
Planned for the future:
Multiple Neuron Layers. EG:
Input --weight-- Neuron --weight-- Neuron --weight-- Neuron --weight-- Output
This allows for more complicated processes and better "brains". Next big upgrade to the brain is also adding random Neurons connected to other random neurons crossing layers and making everything more complicated. Like a neuron connecting the first neuron in a neuron chain to the last neuron of another chain and the middle neuron of a third chain, with different weights to each neuron, receiving an input through all links and giving out an output after it reaches it's overflow point through all links.
The other addition we have is that when a bot reproduces, it has an identical brain BUT gets a slight modification in the reproduction process. (being it the changing of a single weight (or more) or a single overflow point/input/output/connection.
We are also planning to add an input based on the rotation of the closest bot you can see. (If he is directly facing you it is 1 and if facing the opposite way 0)
More to be added later...
Discuss. If you have linux I might post the binary file for you to run it. Windows/Mac are unsupported, because it's just a simulation... and it's a mission to compile it for windows and mac after every update.
So here is what it does:
It generates a "petri dish" for testing, with a food supply on every block. (40 x 40 pixels wide) It then randomly places 20 "bots" which have a basic brain with virtual neurons. (More on that later) If a bot is on a grid space it eats food. If it doesn't get food for a long enough time it dies. If it stays alive long enough it reproduces. (Into another bot of the same color and exact same brain) Food slowly regenerates but not fast enough for all 20 bots to survive, usually only 4 - 5 are left. (Ones with superior "brains") There is also a chance that a new completely random bot spawns into the petri dish.
Now here is how each bots' brain works.
In a bot's brain, there are 20 "neurons" in total. At the moment these neurons are connected directly to input and output. (This shall be improved later)
When a neuron in this brain is generated, it has a random number of inputs. (4 inputs total) One input is how much food is underneath it, the other is the red color of a bot 50 pixels in front of him. (So if a bot is too far he won't "see him") and the last two are for the blue and the green color value of a bot that is close enough to see. All inputs are converted to a number between 0 and . What then happens is that this input gets multiplied by a weight (of a randomised decimal value) and then goes to the neuron. Each Neuron has it's own unique "overflow" point. If the input multiplied by the weight is above this point, the neuron fires an output signal. If the input multiplied by the weight is lower than the overflow point then the neuron stores the value and waits for the next input. (and then adds it to the stored input and if above the overflow point it'd output and if not it would store it like before) There is a choice of random 2 outputs that a neuron can signal too. "Left Leg" and "Right Leg". It can be connected to right, left or both. If both receive a signal then the bot moves forward, if only one leg receives a signal then it would only move forward with that leg. (Turning the Bot)
This is done with 20 neurons each within each bot. (400 in the whole simulation) The best patterns in which they run around in is then the best "brain" and it survives the longest and eventually reproduces.
Planned for the future:
Multiple Neuron Layers. EG:
Input --weight-- Neuron --weight-- Neuron --weight-- Neuron --weight-- Output
This allows for more complicated processes and better "brains". Next big upgrade to the brain is also adding random Neurons connected to other random neurons crossing layers and making everything more complicated. Like a neuron connecting the first neuron in a neuron chain to the last neuron of another chain and the middle neuron of a third chain, with different weights to each neuron, receiving an input through all links and giving out an output after it reaches it's overflow point through all links.
The other addition we have is that when a bot reproduces, it has an identical brain BUT gets a slight modification in the reproduction process. (being it the changing of a single weight (or more) or a single overflow point/input/output/connection.
We are also planning to add an input based on the rotation of the closest bot you can see. (If he is directly facing you it is 1 and if facing the opposite way 0)
More to be added later...
Discuss. If you have linux I might post the binary file for you to run it. Windows/Mac are unsupported, because it's just a simulation... and it's a mission to compile it for windows and mac after every update.