473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing a small battleship game server in Python

Hi there,

for a project in our computer science lessons at school we decided to write a
client/server based battleship like game [1].
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
ones.

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 [2] 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.

Thank you.
Best Regards,
Michael Goettsche.
[1]: 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.

[2]: http://www.amk.ca/python/howto/sockets/
Aug 11 '05 #1
0 2169

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8081
by: C-man | last post by:
Basically I want to create a battleship game that can be played by having two clients connect to it. I was wonder what the best networking principal would be. Basically I suppose I would have to pass an int value or something representing the x,y coordinates of each shot. Should I use some type of Socket programming or RMI or what else should...
5
2554
by: Tlo | last post by:
hello, i would like to do the following, and as i had never used python in a network framework i would like to have opinions on this : i would like to provide some kind of network quizz game, each player logged in and can then join 'playing rooms', in each rooms they had to answers many quizz-like questions, after a game finished each...
15
4461
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do computations, the only data transfered is user mouse/kbd input. It works synchronously, but somehow, when I play in client window, both client and ...
1
2662
by: Jos | last post by:
Hello all. I have a working server, using the asyncore/chat module, which enables logging in, rooms and private messaging. I've used this framework to make some simple games that only required message broadcasting via the server. I'd now like to move the game logic into the server.
3
1707
by: Adman | last post by:
Hi all. I've done some websearching, and haven't been able to find my question answered, so I thought I'd post. I apologize if this has already been answered. My question seems to be a variation of a FAQ. I'm writing a small online game (client/server). The server spits out a steam of data. The data can be described as a Code,...
1
1525
by: iwdu15 | last post by:
hi, im trying to program the game battleship but i cant figure out how to code how people can place the ships and keep track of it. Ive been trying and researching for a couple days now and am at the end of my rope...if anyone cal help thatd b awsome. i have a 10x10 picturebox grid initialized into a 2d array to hold them. i just need to...
24
9368
by: gonzo86 | last post by:
Hey, Im kind of new to C++ and I'm working on making a Battleship program. I need to be able to output a screen with just dots on it for when people havent tried those spots and then be able to switch it with the characters in my array after they have been picked. This is the code I have so far. Right now all all I want to do is make a game...
5
5986
by: muna123 | last post by:
hi, I need help in battleship game here is my code: #include <stdio.h> void draw_game(char board, int maway, int mleft, int score, char prevmove);
11
12455
by: Krzysztof Retel | last post by:
Hi guys, I am struggling writing fast UDP server. It has to handle around 10000 UDP packets per second. I started building that with non blocking socket and threads. Unfortunately my approach does not work at all. I wrote a simple case test: client and server. The client sends 2200 packets within 0.137447118759 secs. The tcpdump received...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.