Writing a small battleship game server in Python
Brian Quinlan
brian at sweetapp.com
Thu Aug 11 12:08:00 EDT 2005
Michael Goettsche wrote:
> What would be a good, but still easy way to write such a server?
You could use SimpleXMLRPCServer. A client call sequence could like this:
>>> s = xmlrpclib.Server('http://...')
>>> token = s.join_game() # blocks until another player joins
>>> s.send_board(
... ['...pppa...',
... '......a...',
... '.d....a...',
... '.d....a.ss',
... '.d....a...'])
>>> s.get_other_board(token) # blocks until other player sends board
['...........',
'...........',
'...........',
'...........',
'...........']
>>> s.fire(2,2)
'Hit!'
>>> s.get_other_board(token)
['...........',
'.H.........',
'...........',
'...........',
'...........']
>>> s.get_my_board(token) # blocks until other guy shoots
['...pppa...',
'......a...',
'.d....a...',
'.d....A.ss', # uppercase if hit
'.d....a...'])
Just designed in 2 minutes - but you get the idea.
Cheers,
Brian
More information about the Python-list
mailing list