[Edu-sig] Life Clock

kirby urner kirby.urner at gmail.com
Sat Apr 22 01:17:26 CEST 2006


We're going to want an easy way to phase in time as the key variable,
which can simply mean a runtime mainloop, ala the usual event polling,
and have objects do an update in situ, meaning they get nudged
forward, one by one:

import jungle
ecosystem = jungle.creation()

# initialize animals
for i in range(10):
    ecosystem.add_animal()

def mainloop:
    while True:
        for animal in ecosystem:
            animal.update()

There's no need to get into threads here.  Develop threads later if
there's a greater need for them.

Then each animal's update method might advance its life clock by 1:

    def update(self):
        self.myticks += 1
        self._internal()

I'm thinking of self.internal as a method for advancing digestion,
doing a sleep cycle, other internal "biologicals" -- perhaps with a
weighted randomizer.

class Animal ( Metabolic, Reproductive ) :

    def __init__(self, mom, dad):
        # birth process
        if self.viable(mom, dad):
            self.genes = self.gene_synth ( mom, dad )
            self.myprocesses = self.startup()
            self.alive = True
        # ...or abort
        else:
            raise ValueError, "No viable offspring"

    def update(self):
        self.myticks += 1
        self.external()
        self.internal()
        if not self.alive:
            # ...  end-of-life code

Alternatively, if we make our animals be internal to the environment
instance, then a single update call to this instance could trigger
individual animal updates internally:

import jungle
ecosystem = jungle.creation()

# initialize animals
for i in range(10):
    ecosystem.add_animal()  # randomizer?

def mainloop:
    while True:
        ecosystem.update()  # advances environment clock, state changes
        # some break or pause condition

Depending on the kind of animal, it would try adapting in whatever
manner.  Tsunami?  Birds take flight.

Kirby


More information about the Edu-sig mailing list