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: leaffurryscaled,
  • 5 for color: redgreenbluebrightdark,
  • 3 for special organs: eyewingtooth,
  • 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

For me the mutator appeared to do nothing.
Ah, yes. If you click it once it will most likely appear to do nothing. It changes one letter in one chromosome. It will almost certainly corrupt one gene. However the other chromosome also has the gene, so the creature will not change. Clicking on "Mutate!" a dozen times though has a very good chance of showing visible effects.

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 :).
It seems that the mutations don't always produce an immediately-visible result. Often I had to click it quite a few times before anything obvious happened. Keep trying!
Took quite a few goes to get a result, then it turned albino, then it exloded then it turned into an egg
Yes, I've noticed that mutations tend to either produce only a slight difference or a very big difference. Interestingly, if you take one of the severely-mutated specimens and breed it with a normal one, many of the offspring look quite normal as well. So it must be just a small difference in the genes that happens to hit a critical spot.
I almost managed to bread an entirely eyeball creature though i juts cant quite purge two tiny fluffy spots
The gene for an eye is BDABDACADDBABCD. You could try splicing it in randomly, or at the start of all body parts (they are started with the DDDCDCBCDD gene). Let me know if it works :).


Those are some of the creations, including the eye creatures, an upside down black bunny and a few pokemon kind of things.
Thanks for the feedback and the generous ratings! I'm surprised by the number of reports of segfaults. Sorry about that. I packaged Pyglet from the svn head so maybe there is something wrong with that. I just might install a Ubuntu and try to track it down.

Congratulations everyone and especially the winners! Looking forward to seeing who they might be :).
Breakthrough!

I can export GIFs now!