Solved

Developing a 2 player game on linux server help

Posted on 2011-03-24
4
497 Views
Last Modified: 2012-05-11
I am a student andI need to implement a 2-player PacMan game (in C) for a Unix Machine. Each player will login into the same server with their respective user accounts, type the command ‘pacman’, and instantly will be placed in a FIFO queue (fifo.c) and wait for access to the game. When it is their turn to play, both users should find themselves in the ‘same maze’, competing against each other.

I did not implement the FIFO queue yet. Up till now, I have a one-player pacman game, pacman.c and in it I already have an IPC between player one and the ghosts via shared memory. Now, I would like to implement another IPC between player 1 and player 2, and I was thinking of using signals but I am not sure whether they are practical.  

Can I assume that one instance of pacman.c is loaded on the server? Therefore, is it possible to load only one instance of the game (fifo.c will call exec() ONCE) and associate different processes (in pacman.c) with different user accounts (one process associated with player one, and maybe the child process with player 2)?

 

0
Comment
Question by:emcict
  • 2
4 Comments
 
LVL 45

Expert Comment

by:Kdo
ID: 35206550
Hi emcict,

Signals might be useful within the application (client program) but they aren't much help with the communication to/from the game server.

You'll have to establish a "turn protocol" with the server.  The application will query the server with a simple "is it my turn" question.  If not, the application pauses slightly and resends the question.  When it is this players turn, any update of the game (player position, board changes, etc.) will need to be sent to the application (probably by a different question/message type from the application) and then the turn taken.

What you're describing seems like an awfully complicated way to do this.


Good Luck,
Kent
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35208180
We did a project much like this in our OS class. We ran the game on the server and just sent the board position to the clients and accepted the input (we used sockets). Of course, we sent raw position data to the clients and rendered the graphics at the client.
The reason we did it like that was that we were using UDP so that if any packets were dropped, the game just skipped, it didn't make the two clients see totally different games.

I don't see how a "turn protocol" would work for pac-man since it's real-time. But as you've probably noticed, there's a window of time between when you need input (when pac-mac is between intersection points on the grid). So you could just accept one input packet in each period and drop the rest.
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 125 total points
ID: 35260206
My 2 cents, rather than having multiple client programs communicating between each other (player 1, player 2, ghosts) you should implement the game server to do all of the tracking and to house all of the data structures (along the lines of Tommy's suggestion) and your clients should simply handle the user input and displaying the game. There should be one copy of the actual gameboard, on the server process. Could be in shared memory allocated by the server and attached by each client, or you could do all communication via IPC.

As far as signals, you don't need them for this. Since you aren't using TCP/UDP for everything, we would simply use shared memory and semaphores to control access to the central game structures.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35260610
Ah, yes. That's good advice. Shared memory isn't really realistic for most Client-Server applications, but if that's what you have then use it! It actually makes it a lot easier. You just need a queue for input commands that the clients add to and the server consumes.
I wasn't really paying attention when you said you had shared memory. I just assumed your project was like mine. Most of my earlier comments still apply though, but the server doesn't need to send the board position, it can just write it to the shared memory.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now