Paolo Crosetto wrote:
Dear all,

I am writing an application in Python for an experiment in Experimental Economics.

For those who do not know what this is: experimental economics uses controlled, computerised lab experiments with real subjects, putting the subject in a game mimicking the situation of interest and collecting behavioural data about choices made.

Hence, experiments involve the use of a multi-client architecture with one server, and are sort of online games, with actions taken by clients and computation, data collection, etc... handled by servers.

I chose to use Python because I needed something flexible, powerful and easy - I am a beginner programmer.

My game is a sort of scrabble, with palyers buying letters and producing words or extending existing words. I use a pipe to ispell -a for spellcheck, XMLRPC for the server-client infrastructure, and have developed all the rules of the game as server functions, called by a client. States of players and of words created are stored in instances of two basic classes, Player and Word, on the server side.

The problem I now face is to organise turns. Players, as in Scrabble, will play in turns. So far I have developed the server and ONE client, and cannot get my head round to - nor find many examples of - how to simply develop a turn-based interaction. I basically need the server to freeze in writing all the clients while client i is playing, then when i is over passing the turn to i+1; clients are still accessible by the server at any time (the payoff of a player changes even as she is not playing, by royalties collected from other players extending her words).

In another thread (about a battleship game) I found two possible leads to a solution:
1. using 'select'.
2. using threads.

But in both cases I could not find any clear documentation on how to do this. The 'select' road was said to be the easiest, but I found no further hints.

Does anyone have any hints?

As I understand your description, the server and each client will be a separate process on a separate machine (once deployed), so threads do not seem applicable. (For development, you can use separate processes on one machine communicating through sockets just as if they were on multiple machines.) As I understand select, it is for select *any* available client input, not just one in particular. I believe the standard solution is to define a 'turn token' and write the clients so that they only do 'turn' activities when and only when they have that token. I presume you do not need to worry about players trying to cheat by rewriting the client.

tjr

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to