Tuesday, April 7, 2009

DevDiary: Artificial Life updates coming soon

I've been working on some changes recently to the Artificial Life iPhone app. Some of them have already been submitted to Apple and should be approved any day now.

The most recent submission includes support for saving the world state when the app exits along with having the protozoa grow in length as they attack others or eat. These two changes are in the pending update now.

The following describes some more upcoming changes that weren't ready in time for this latest app update, but will definitely be in the next (since they are working now):

I changed the graphics slightly - the creatures now are semitransparent and they pulse slightly, giving them a somewhat jelly fish look. It was mainly done as a test to see how practical it is to have all the creatures represented as bitmap images rather than just dots. It appears the graphics engine is pretty capable of keeping up - according to Instruments, I'm only using about 20% of the graphics power.



The main slowdown in the app is actually caused by the creatures' artificial intelligence routines. The slowdown is exponential in relation to the population. Each creature has to search through the list of all the creatures in the world when making decisions. So, 50 creatures means 2500 decisions. 100 creatures and the number jumps to 10,000. 300 creatures and it's 90,000. Obviously that's not an ideal way to process the AI.

For those interested, this issue is called the "nearest neighbor" problem. You can read about it on Wikipedia. It's a well studied computer science problem.

To address this speed issue, the world is now divided into a 9x9 grid and the creatures are put into one of 81 bins depending on their location. (Anything out of range of the 9x9 grid is put into the closest edge bin). For finding their nearest neighbor, a creature now only looks in the 3x3 grid area of its current location. This gives a significant boost in speed in the app. While there is still a noticeable slowdown when you reach the 300 protozoa maximum, the slowdown is much more tolerable.

I've also implemented a small particle system for "special effects" in the app. Now, when a protozoa gets killed by the sun, or is attacked by another protozoa, there will be some minor particle effects generated. You can see a sample here in this short video.






controller="true" loop="false" bgcolor="#000000" pluginspage='http://www.apple.com/quicktime/download/'>



And finally, the last change made was to have the protozoa's initial diameter be based on its age. So, when one is newly born, it is very small and will increase in size as its age increases. It reaches full size at at 40.

Again, I should mention the first two changes - saving the world state and protozoa growing in length - should appear in the iTunes App Store any day now. The remaining changes will most likely be submitted in a week or so.

5 comments:

Anonymous said...

Hi - just thought that I'd leave a little feedback to let you know how much I love this little sim! I've had a background in biology - although I'm not in the field any more - and I've had a dream of creating something like this for years... unfortunately my coding (in-)ability has meant that it's never got of the shelf :)

There's a few things that I'd really like to see - not sure how plausible any of them are, but hey, a requirements document is only a glorified wishlist...

1) Ability to specify starting chromosomes per colour of protozoan
2) Ability to "seed" the world with a particular number of protozoa of specified colours, perhaps defining "spawn sites"?
3) Ability to adjust the chromosome mutation rate
4) Dominant and recessive chromosomes
5) Identification of selected protozoan's "classification" (predator, scavenger, etc.)
6) When spying on a protozoan, have the ability to indicate which other protozoan or object (food, sun, hiding place) is being referred to in the rule calculation (maybe only if paused to reduce lag and excessive updating?)
7) Ability to "trace" a protozoan's family tree - its descendants and parents (again, maybe only if paused?) and ability to see which chromosomes have been passed on
8) Option to change the orbit radius of the hiding places
9) Option to remove all food from an area (like the zapper) or to add food to a specific area
10) I can't work out whether it's already doing something similar, but some kind of visual representation of the number of times a protozoan has reproduced would be handy. Is the tail length controlled by age, or number of "feeds" or something?

I'm sure that there are load of other cool features that I could think of suggesting - at the risk of causing application bloat! - but I think I've gone on enough already :)

All the best - and keep up the great work!

Mark P.

(OK - one last thing... any chance that the codebase would lend itself to a Mac desktop application, or perhaps a screensaver??)

Mostly Torn said...

Hello Mark,

Thank you for the kinds works about the Artificial Life app.

Those are a lot of interesting ideas - some more easy to implement than others. Hopefully some of them will find their way into future versions of the app.

Regarding item #10, the length of the protozoa is determined by how many times it either attacked another protozoa or ate a piece of food. However, the length is currently set to an arbitrary limit of 20 segments.

Anonymous said...

this app is very entertaining. here are a few ideas
that i think would be intresting.

1.have a parasite species that clings to he tais of other species and eat them and reprouces on them
2. a counter that keeps track of the individual color/species of protazoa
3. when you spy on one protozoa the screen follows it by itself

Nathan said...

I think you should add or consider these things, plus most of what anonymous said.
1. Have a maximum and minimum speed slider, and have maximum and minimum speed abilities be inherited. Iv noticed the protozoa sometimes have trouble interacting, such as attacking, eating and mating because they rarely slow down. Obviously the protozoa that have a wider speed range will survive better
2. Have a secondary aesthetic feature that will cause the appearance of protozoa to mutate with successive generations, perhaps only slightly. Shouldn't had much actual effect but it'll still be neat.
3. The ability to adjust mutation rate, as anonymous said
4. Running commands, such as "if *Protozoa heading for food/hiding/fleeing* then...
Wider variety of commands, such as heading towards or away from the nearest/farthest protozoa, and being able to attack the nearest rather than only the weakest
6. Two part commands, such as "IF *protozoa heading for food* AND *distance to nearest Protozoa* IS *...* THEN *attack nearest protozoa

Spencer said...

There should be suggestions on how to set up a good Protozoa. Or exact configurations of the traits of the protozoa on the website or in the app that will work well. The longest my protozoas have lived was around 2000.


All content copyright © 2009  Brian Stormont, unless otherwise noted.   All rights reserved.