New levels

New levels have been added to the game.

L1

the new first level

L2

another basic one

There are also some levels that are bigger than the screen.

L5A

what the player initially sees

L5B

the rest of the level revealed when the creature goes to the right

To deal with panning the “camera” what the code does is it tries to put the creature at the centre of the screen by setting an X and Y offset, but before effectively doing that (moving the world in relation to the screen) it checks what is the maximum and minimum offset limit of the current level. For example, if the whole level fits the screen, the maximum and minimum offset limit should be 0 for X and Y, and therefore the “camera” would not move. If the level is bigger than the screen horizontally, the X offset limit should be proportional to how much of the level exceeds the screen size.

Some other aspect implemented is that the initial set up for the creatures’ characteristics and its DNA is now part of each level’s specification. This includes information about mutation chance, mutation amount, quantity of jumps allowed, maximum jump impulse, etc.

This makes sense because we might, for instance, want to allow each creature jump more times in a bigger level than they would in a small one. Or maybe let the creatures mutate more and more frequently in a level where jump precision is not important, and less where the jumps should be finely tuned.

How will the game look like?

To answer that question, even to myself, and to have a better idea of how the game mechanics will be I made a series of drawings. Here they are:

1. Level and initial creatures

Image

Here the level can be seen and the generated creatures are represented inside squares on a row at the top left of the drawing. Each creature is identified by a number.

2. Third creature after its trial

Image

Here a creature is shown in the level after jumping five times. It is the third one, as the arrow on the top left is showing. Thin arrows illustrate the trajectory of each random jump previously performed by the creature.

3. The player selects the winning creatures

Image

Here the player drags creature number 7 to a slot on the column to the right, where the selected creatures will be. As shown on the next drawing, the player can choose the same creature several times by dragging it to more than one slot (if the player could only choose any given creature once, the selected set would be the same as the original set).

5. All slots filled and ready for the next generation

Image

With all the slots filled, the player has the option of going to the next generation. The next generation will be formed by nine new creatures, each one based on the corresponding creature on the slots to the right. Taking the drawing above as example, the new creature on slot 1 on the generation to come will be a possibly mutated version of creature 7, because creature 7 is the one occupying the first slot on the column to the right.

Here we should note that the player was able to drag two creatures into one single slot, instead of just one (on the column to the right containing the selected creatures, notice the slots that have the word “mate” in front of them). In this case, the two creatures will mate in order to make the new creature, and then the new creature will be subject to mutation just as the ones bred from one single creature.

Very early stage prototype

After doing some drawings to figure out how a level of Evolution Nine should look like, I used Box2D to draw what could be the first level and then put a rectangle jumping about randomly on it.

First I did it by creating one more test to the Box2D Testbed application, but after switching the project from Box2D/C++ to Box2dWeb/JavaScript on HTML5’s canvas I rewrote it accordingly.

Here is what it looked like:

prototype screenshot

I did this by modifying the demo.html file included with Box2dWeb.

A link for a newer version of this prototype will be up soon.

First test with genetic algorithms

What can be seen on the video are 10 lines that evolve so that their tips get closer to the target. When the target is moved by the user, the lines follow.
After every frame the best 5 lines, that is, the lines with tips closer to the target, are selected to continue to the next frame. They are duplicated and all of them are subjected to mutation. When the lines get mutated their joints’ angles change a little. Before the next frame the selection of the 5 best happens again and the process repeats. This process drives the lines’ tips closer and closer to the target.

On the video you can see all the lines being reset several times. When this happens they all are regenerated and start with totally random positions but quickly converge towards the target again. It can also be observed that the number of joints are increased and decreased sometimes, and some aspects of the drawing are changed (curved lines are replaced by straight lines, black dots appear on every joint).

This is my first experiment with genetic algorithms. This application was done so that I could put to practice some of the basic principles of genetic algorithms and also learn more about them.

After I came to the idea of making a platform game using genetic simulation on it, making a test applications using those algorithms was a good way to see them working in practice and start having ideas of how to use them on the actual game.

The application was made in Xcode using openframeworks with a modified version of the ofxDna add-on.