Inspired by NASA Jet Propulsion Laboratory's OnSight project, I created this program in Unity3d with C#.
The program takes a heightmap in .png format, and generates the Gale Crater. The model is generated dynamically,
by placing vertices in the 3D space and creating a mesh surface using triangles.
This
article shows the detailed steps.
You can download the source code
here.
The goal of this project is to train a computer program to play a level of Angry Birds and complete the level successfully
by eliminating all the pigs.
In order to keep the game simple and interesting, I allow he AI to have three yellow birds. I chose the yellow
bird because it has a boost activation feature which allows the bird to increase its speed when activated and
cause more damage. When it is used in a smart way, yellow bird can cause a lot of damage.
First I built a simple Angry Birds clone in Unity3d, with some physics handling code but that is another tutorial
and is in the scope of this project.
This is called the 8-queens problem.
8 queens should be placed on a 8 by 8 chessboard in such a way that none of them should be attacking another.
To solve this I implemented a genetic algorithm.
First, a population of candidate solutions (individuals that look like colorful cubes on the right side) are
randomly created. Individuals that have higher fitness score, are taller than others. Usually the initial population
is far from being close to the optimal solution(no queens are attacking each other). You can consider them as
a specie that is struggling to get by in their environment.
Each individual has a set of genes and they are represented with different colors. In this case each gene represents
the position of a queen in a certain row (1 to 8). For example a yellow gene represents a queen that is placed
on the 4th row of the chessboard.
Each cube represents a way to place 8 queens on the chessboard on the left side. The next step is to choose
individuals and mating them to produce off-springs. Individuals can mate with a probability that is proportional
to their fitness level.
This makes better performing individuals more likely to mate. Therefore there will be more off-springs coming
from fitter individuals. An offspring is the result of this mating. Some of his genes come from the father and
the rest comes from the mother. This is called cross-over. The off-spring will replace the individual that has
the lowest fitness score in the population (A mean way to control population).
After repeating this process many times, it is possible to reach an optimal solution. In this case an optimal
solution was found. Though it is not always guaranteed.
However you can observe that in time a population adapts better to its environment. The average fitness score
of the population is way higher than the initial population. This is similar to the situation where the specie
I mentioned above becomes much more adapted to its environment.
Looking at the population in the video, you can see that genes coming from fitter individuals eventually takeover
the population. Mechanisms of evolution seem to work in computational environments, they probably worked in real
world as well