chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] State machine using call/cc


From: Joel Reymont
Subject: Re: [Chicken-users] State machine using call/cc
Date: Wed, 8 Dec 2004 13:14:57 +0000

> felix winkelmann wrote:

>IMHO each player would have his/her own continuation, with it's
>lexical context containing enough information to know about the
>actual game in progress (like some local variable holding a record
>representing the current game).

The server keeps a list of running games and a list of players. There's a
state machine associated with each player and one is created for each game. 

A game has a list of players and keeps track of whose turn it is and what
actions they can execute. I add players to a game when they decide to join it.

The player state machine keeps track of whether the player is logged in
or not and restricts what they can be at any given time. For example, a
player can only logoff if they are logged in and they cannot join a game
unless they login first. 

A player can be either idle (hanging out in the lobby), observing a game
in progress (watching) or playing. Once they get into the playing state
then all requests are passed to the game state machine. When they choose
to leave the game they get back into the lobby and the idle state.

>If you explicitly keep continuations for each possible game-state
>(independent of the player), you might be better of using normal
>procedure (tail-) calls (google for Shriram Krishnamurti's "The Swine
>before Perl" talk to see some slides about it).

Yes, I got slides of Shriram's talk. I don't know if I need to keep
continuations for each possible game state.

>But (if I understand you correctly) it would be better to execute a
>game in a normal "procedural" fashion (do this, then that, etc.) for
>each player, with carefully placed calls (actually continuation-returns)
>back into the main-loop (the dispatcher), saving the current state
>of the game in the shape of a continuation in some global table.

Well, games proceed from one state to the next. First a game needs to
gather enough players (state #1). There's a timeout of 15 seconds before
the game starts (state #2) and in that period of time more players might
join or some might leave. If there are enough players at the end of state
#2 then game proceeds to state #3 and figures out who makes the first
move. It then goes to state #4 where it notifies the player that they
need to make a move and waits for their response a given number of seconds.

I haven't thought of how to do timers in Scheme yet. Maybe I would let
Scheme call into C++ and say "schedule an event in X seconds for this
game and notify me".

>To see something that is (remotely) connected to this problem,
>take a look at Chris Double's nice demonstration of continuations
>based web-programming, which is somewhat related to what
>you describe:

Yes, I'm looking both at the modal web server and at the call/cc tree
walking example (tree->generator) in Teach Yourself Scheme in Fixnum
Days. I'm trying to put the two together.

    Thanks, Joel

-- 
OpenPoker: The Linux of poker software
http://wagerlabs.com/forums






reply via email to

[Prev in Thread] Current Thread [Next in Thread]