Lab Lab Bunny Lab: Behind The Scenes
As I played a bunch of PyWeek games during the weekend I found the postmortems detailing the intricacies of the games and their development a great read. They also spawn good discussions of what is missing and what could be changed. So...
Genetics
Lab Lab Bunny Lab's creatures are defined by their virtual DNA. This DNA is a string made up of ABCD characters. Some sequences carry meaning. These are the genes.
It appears the final version has 19 genes:
- 3 for texture: leaf, furry, scaled,
- 5 for color: red, green, blue, bright, dark,
- 3 for special organs: eye, wing, tooth,
- 4 for controlling the shape of a body part: inflate and shrink control the radius, contract and widen control the eccentricity,
- 2 rotate the body part clockwise or counter-clockwise,
- one starts a new body part and another concludes the description of a body part.
The sequence of genes is very much like a turtle program that describes how to draw the creature. To make it more interesting there are a few special rules, for example:
if material == 'furry': if r and g: # Brown is dominant. b = 0 g = min(r, g) elif material == 'leaf': if g: # Green is dominant. r /= 2 b /= 3
Inheritance
The creatures actually have two homologous chromosomes. Two strands of DNA that are read in parallel. The gene sequence of the creature is the merging of the gene sequences of the two chromosomes.
When you mate two creatures they each create one "mixed" chromosome by crossing over their own chromosomes at random points. The offspring gets one mixed chromosome from each parent.
Exercise
This setup makes it possible to observe Mendelian inheritance. Put a bunny in the mutator and press it until something notable happens. Say a leg becomes brighter. This could be explained by damaging the dark gene of the leg on both chromosomes or by manifesting the bright gene on one chromosome by good chance.
Let's figure out which is the case! Clone the mutated rabbit and breed it with its clone. (Yeah, sex chromosomes are not simulated. Makes experimentation easier... and weirder.) If the dark gene was destroyed none of the offspring should have a dark leg. If the bright gene was added it should be inherited by 3 out of 4 offspring. This is because each parent passes this gene on with a 50% probability and if either of them does, the offspring will have a bright leg.
This is already Mendelian inheritance but you could carry on crossing specimen from later generations and verify the statistics predicted by the theory. Gregor Mendel cultivated 29,000 pea plants — see if you can make do with less!
Regrets
I have basically managed to finish one of three pillars intended as the basis of the game. The missing two are:
Intermediate genetic manipulation. The Digitalizer gives absolute control but is no fun to use. I had planned some tools to fill the gap between the Mutator and the Digitalizer. A Sequencer that would report the list of genes found in a DNA. An Autopsy service that would destroy a creature and provide body part-level information (maybe break up the DNA into per-part fragments). A Retrovirus designer that would allow you to replace some sequences with others in a creature.
Outside world. An environment into which you can throw your creations and have them solve problems. You could control them through a Controller where you bind sequences to keys on your keyboard. Pressing the key would activate the part that has that sequence. You would capture new creatures (with exciting new genetic material) from this outside world, probably by beating them up.
I am not sure how I could have fit these in the week. I am not Cosmologicon :). I probably aimed too high. Tuning the genetics soaked up a lot of time and it could not be skipped since it is the core of the game. Features that can soak up indefinite amounts of time are the number one enemy in PyWeek in my opinion.
I also spent quite some time on the UI. I did not use a toolkit because I can write the line for checking where the user clicked faster than I can figure out a toolkit. Turns out a UI with drag and drop, vertical and horizontal containers and all this stuff is a bit more work — looks like it clocks in at 300 lines. Also it took me ages to draw the graphical elements. And I don't even have a button click animation!
Ah, and I only realized on Saturday that saving the game is not as easy as pickle.dump(game, file('save_game', 'w')) when every object references a few sprites :).
(log in to comment)
Comments
So just click, click, click, click! You don't have to wait for the sound to finish, click as fast as you like.
I really should have put this in the help box. It's just one of those things that is so obvious to the creator that they don't see how unintuitive it will be for new players. Sorry. I bet the feedback I get will be full of this :).
Those are some of the creations, including the eye creatures, an upside down black bunny and a few pokemon kind of things.
Congratulations everyone and especially the winners! Looking forward to seeing who they might be :).
I can export GIFs now!
Hugoagogo on 2011/09/27 06:48:
For me the mutator appeared to do nothing.