StrangeWorld
Author: Chaplin
E-mail: chaplin_hack@hotmail.com
Webpage: http://www.angelfire.com/id/chaplincorp
StrangeWorld is a java program that demonstrates how evolution through natural
selection can tune a neural network. StrangeWorld models a predator/prey
environment where herbivores feed on static
food and carnivores feed on herbivores and other carnivores.
- Foods for herbivores
are depicted as green circles. There are spawned following a certain rate
and have random positions. They do not possess neural networks and do not
move. Their purpose is to feed herbivores.
- Herbivores are shown as blue circles with a tail
indicating the rear of the animal. Herbivores
feed on food grown randomly in StrangeWorld. They possess neural networks.
- Carnivores are rendered the same way as herbivores but have a red color. They feed on
herbivores and other carnivores. The also possess neural networks.
Neural Networks
Every carnivores
or herbivore has a set of antennas. Each
antenna calculates the Red/Green/Blue
intensity inside a certain radius. Intensity increases, as it is closer to the
animal. These are the values that the animal uses to make decisions on whether
to move forward or backward or to rotate.
The neural networks that the herbivores and carnivores in StrangeWorld use are simple analog
neural networks whose neurons can have a value between -1000 and 1000 as its output.
There are nine neurons per layer and there are 5 layers (1 input,
3 hidden, 1 output).
Every neuron of a layer is connected to all the neurons of the previous layer.
Each inter-neuron link can have a weight between -1000 and 1000. The inputs for
each neuron are multiplied by their corresponding weight then added. The total
is then divided by the average of all the weights for that neuron and the
result cropped into a range between –1000 and 1000 is the output of that neuron.
The nine inputs of the neural networks
- The red
intensity from the right antenna (0 – 1000)
- The green
intensity from the right antenna (0 – 1000)
- The blue intensity
from the right antenna (0 – 1000)
- The red
intensity from the left antenna (0 – 1000)
- The green
intensity from the left antenna (0 – 1000)
- The blue
intensity from the left antenna (0 – 1000)
- The current health of the creature (0 – 1000)
- The last rotation (feedback) (-1000 – 1000)
- The last displacement (feedback) (-1000 – 1000)
The two outputs of the neural network
- The rotation (-1000 – 1000) or (-10 – 10 degrees
rotation)
- The displacement (-1000 – 1000) or (-10 – 10
pixels displacement)
Rules of Strange World
StrangeWorld is clocked by a
global tick. Every tick, the world iterates through all the creatures.
- For every creature, its health is decremented by
1. If it reaches zero, then the creature dies.
- If the creature is not dead, StrangeWorld first gets
the Red/Green/Blue intensities from its two antennas and pushes
their values in its neural network, it then takes the creature’s health,
last rotation and displacement and pushes those values into the creatures
neural network.
- It then ticks the creature’s neural network,
which then makes a decision on its next displacement and rotation.
- StrangeWorld then takes these two values from
the neural network’s output layer and moves the creature accordingly. The
creature will rotate between 10 and –10 degrees based on the rotation
output value from its neural network. It will also advance or step back
between 10 and –10 pixels based on the displacement output value from its
neural network.
- The creature’s health is decremented proportionally
to its displacement. The more the creature moves, the more energy it
loses. Rotation does not affect its health.
- If the creature comes into contact with another
creature and that creature is edible, that creature is killed and the
current creature is awarded some energy.
- If the creature is a carnivore
and this is its 10th victim, that carnivore
reproduces and creates three offspring each inheriting its parent’s neural
network topology with slight mutations. An herbivore
reproduces and spawns two offspring every time it eats a food.
Interface
Everything in StrangeWorld
is manipulator with the mouse. The program was created using the Java SDK
1.4.0. If the JRE is older than that, the mouse and keyboard inputs may not be functional.
First, keyboard focus must be given to StrangeWorld; clicking inside the window
does this.
A single creature can be
selected by clicking on it. A selected creature turns yellow and is invincible
for as long as it is selected.
The following keyboard
commands are available.
- ‘h’ turns on/off antialiasing.
- ‘r’ turns on/off the rendering. Without
rendering, the processing is done much faster.
- ‘b’ changes the background color between black
and white.
- ‘g’ turns on/off the impact of a creature’s
health on its color.
- ‘l’ switches between rendering creatures as line
or as circles.
- ‘p’ pauses/starts the processing in StrangeWorld.
- ‘v’ turns on/off the rendering of every creatures’
antenna range.
- ‘k’ set’s the selected creature’s health to
zero. To kill a creature, pause StrangeWorld, select that creature, press ‘k’,
unselect it and then un-pause.
- ‘w’ turns on/off wire frame rendering.
Saving the progress
When StrangeWorld is closed,
it dumps to the current directory the neural network gene for one randomly
selected carnivore and one randomly selected
herbivore.
These neural network genes
are then loaded next time StrangeWorld is started. If no gene files are found
on startup, the creatures that are spawned start with completely random neural
networks. The genes are also saved every 5000 ticks to minimize the loss of
progress in case of a system crash.
Extinctions
In the case of an extinction,
StrangeWorld will spawn three new creatures of the extinct specie with the
specie’s last creature’s neural network. This allows StrangeWorld to continue
to run non-stop without having to be restarted every time there is an extinction.