Writing a small battleship game server in Python
mail at tuxipuxi.org
Thu Aug 11 17:46:15 CEST 2005
for a project in our computer science lessons at school we decided to write a
client/server based battleship like game .
I know this game could be written without a server, but the whole project is
for educational purposes.
Being the initiator of this project, I thought I would write a skeleton for it
before we actually start with it. The client thing won't be too hard, what
I'm having problems with is the server, maybe because I have problems
understanding what's the best way to accept connections and handle existing
So, here is my problem:
The server should accept connections from new players and be able to handle
multiple games concurrently. The main purpose of the server will be to make
sure the clients follow the rules(only shoot once, shoot only existing
fields, ...) and inform clients about game end etc..
What would be a good, but still easy way to write such a server?
In a socket tutorial  I read the usual way to write a server is to create a
server socket and then listen for connections in an infinite loop. I
understand that part, but how should I handle connections then?
Start a thread for each game and put every two new players in it?
Or does Python offer a better solution to do this?
Twisted can be a solution too, but this server should run on standard python
installations and Twisted might be a bit too heavy for our project.
: For those who don't know the game:
It's played by two players. Each player has a game board where he places a
predefined number of ships. After placing the ship, the players try to shoot
the enemy's ships (but they don't know where they are). The game is
round-based, so player A may shoot once, then it's player B's turn and then A
again and so on until one player has shot all ships of the enemy.
More information about the Python-list