This was exciting.
The project consisted of several parts:
Finally the .tga files were joined to a single .avi file with
animmaker; the soundtrack
was encoded to mp3 with LAME
and these two were combined to a divx encoded .avi file with
- - povray script to simulate a tetris field.
- I made this kind of macroes:
#macro addblock(blocktype, xpos, ypos, rotation)
Adds a tetris block to the scene, rotated in the specified angle.
#macro eraseline(linenumber, clockpos)
Destructs one block line of the scene: Clips the scene to upper half
and bottom half, explodes the block in between and moves the top half
a bit downwards. Clock position given.
This made it easy to define a field. Example:
addblock(L1, 0,areaheight-3, 90)
addblock(V, 2,areaheight-1, 0)
addblock(K, 5,areaheight-2, 180)
addblock(S1, 7,areaheight-2, 0)
addblock(L1, 2,areaheight-3, 0)
addblock(S2, 4,areaheight-4, 0)
addblock(S2, 7,areaheight-4, 0)
addblock(L1, 2,areaheight-5, 90)
addblock(V, 1,areaheight-8, 90)
The downside of this was that it made the rendering crawling slow.
Despite of my best efforts to optimize the scene so that there were never
invisible objects in unions, some frames of the animation ate hundreds
of megabytes of memory (which of 70% was swap) and ate hours of rendering
time. Seems like povray sucks at unions.
- - music.
- Years ago I wrote a music (MidiS3M with Scream Tracker 3) which seemed
to fit quite well in this animation. I rebooted to Windows, played and
recorded the music, returned to Linux and encoded it as mp3.
- - sound effects.
- The sound effects were MIDI instruments which I recorded the same
way as the music.
- - mixer.
- This program is available for everyone to
The program inputs a list of samples and timestamps to play
and then mixes them together at the specified times.
- - tetris computer player.
The first time I have implemented a genetic algorithm.
I made a tetris game engine, then implemented a computer player
to calculate the next move.
The computer player judges all possible moves and picks the
The problem was how to judge which move is the best.
So I assigned various properties:
The program had some initial values for each of those
properties. The computer modified each of them a little
and played games using each of these scoresets. Those
scoresets which survived best, were minorly altered and
those which survided worst, were majorly altered. This
was repeated for hundreds of games, hundreds of iterations,
hundreds of scoresets, until I was satisfied with a computer
player that played 100 times better than with my initial
- How many windows horizontally
- How many windows vertically
- How tall heaps
- How thin/deep pits
Next the computer player was only needed to play one game
and save the actions of the game to a file.
- - scene generator
- This program reads the saved game produced by the computer player,
and converts it into two files:
- Povray script (addblock, eraseblock...)
- Mixer script
- - makefile
- A Makefile to combine all of these into a serie of thousands
of .tga files.