[Stackless] Make the Stackless Scheduler Your Friend Re: Realistic ticking and acting
Andrew Francis
andrewfr_ice at yahoo.com
Fri Jul 14 18:45:22 CEST 2006
Hi Kai:
Like Grant stated, I think you are making things too
complex. Also you are forgeting that Stackless works
best as a cooperative threading system.
>Each step I take I seem to encounter these sorts of
>problems. Remember, this is not real-time code. It's
>not about sending a tick every X
milliseconds/seconds, >it's about sending a tick when
all the actors have >executed their actions for that
tick
I will assume the reason you assign ticks to actions
is because some actions take longer than others, so
the "world" or "environment" may change. And this may
put a robot at a disadvantage.
Grant Olsen:
> I really do think you're making things more complex
> than they need to be.
> + Tasklets are added to the schedule in the
> order they're created.
> + A tasklet gets moved to the end of the queue
> if it reschedules itself.
As Grant pointed out, the Stackless Scheduler uses a
simple round-robin algorithm. Based on what you said,
I would suggest that a round correponds to a 'tick.'
Kai, I would suggest that rather than fighting
Stackless by trying to break up actions with a
pseudo-scheduler, I would sooner control the robot's
world view and ability to act. Say a robot begins an
action, say THINKING at time t. The robot bases its
computation on the environment(t). Then the robot has
finished thinking, its next computation is based on at
environment (t+compute_time)
Another result of this approach is rather than
building a scheduler on top of a scheduler, you can
now focus more closely on the game logic.
consequently an algorithm for an actor could be
"""
if the Game allows me to take a turn, I will. This is
indictated by my World changing.
"""
class Action(AbstractAction):
def execute(self, the_state_of_the_world):
if self.canDoAction(the_state_of_the_world):
do_some_computation
else:
pass
return
class Actor(object):
def execute(self):
while(some_condition):
if (not queue.empty()):
action = queue.pop()
action(game.getWorldState(action, self)
schedule()
else:
break
If the "Game" sees an actor perform a "Think", it will
tell that actor not compute an another action for a
given number of 'ticks.'
I know this really does not solve the immediate
problem (I find generators mixed with channels a bit
hard to to follow)
Also look at the Nancy Lynch solutions using
synchronisers in her book "Distributed Algorithms",
chapter 16. All these use message passing.
Cheers,
Andrew
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list