Wednesday, October 10, 2007

Free Time Programming

Over the break, I had a significant amount of free time that I could spend making a good program for fun, not for class. So, I did. I made a world with one species of plant, one species of herbivores and one species of carnivores.

They have rather simple behaviors. Plants just throw off seeds every so often. For the animals, it's a little more complex. If they see something that can kill them (in the case of the herbivores), they run away from it. If they see something they can mate with (For herbivores, an herbivore of the opposite sex. For carnivores, any other carnivore - they're hermaphroditic), they move towards it and mate with it. If they see something they can eat, they move towards it and eat it. If there aren't any of those things, they move around to look for them.

Here's a screenshot. The green dots are plants, the blue dots are herbivores, and the red dots are carnivores. On the right side are the population and average genome of the three groups.

Yes, genome. Every individual has its own genes that determine things like how fast it moves or its range of vision (for animals) or how frequently it throws off seeds and how many seeds it throws off when it does (for plants). A parent will pass its genes onto its children with a small chance of mutation.

Although this all works properly as I programmed it, there are some things I should change the next time I have time. The most obvious, and easiest to fix is that of instant gestation and maturation. That is, as soon as two creatures mate, there the offspring is, and fully grown at that. No pregnancy and no period of youth.

Also, there should be more genes. Genes that determine things like how likely a gene is to be inherited from the father or mother, so it's not a static 50% or genes that determine how likely a mutation is to occur.

And what is to me, the most important (and hardest) change is to make behavior much more flexible. For example, mating is always given a higher priority than eating, even if the creature is literally starving. I'd like to change that so they can decide to do different things in different circumstances. Those could also be inheritable traits.


This is a screenshot from the same simulation as before, but significantly later.

1 comment:

Nox said...

Dude, that's pretty cool... Um, what programming language did you use?

I've always had a lot of fun programming something, especially when it works, but I've never had time to learn any languages before now. Maybe I can convince myself to stop being lazy ^_^