Sign in to follow this  

[web] Storing Game State

This topic is 2834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am creating a turn based online strategic game similar to Empire Deluxe using Silverlight and WCF as my web server. I also have SQL and SQL Express available if I need to use a database. My question is what's the best way to store the game state on the server side? Are there any good articles on this? Each time a player does a action the server will have to validate, process and update the state returning the result to the client. Does the server need to pull the entire state of the game each time a player makes a move? Obviously I shouldn’t store the entire game state in memory on the server since you never know when a player will make their next move and there could be hundreds of games running simultaneously. Any pointers would be appreciated. Thanks, --Mike http://www.flaired.com [Edited by - silverlightDev on March 11, 2010 4:05:18 PM]

Share this post


Link to post
Share on other sites
I'm guessing you would have the following table layout, as a start:

ActiveGames
- ID (int) PK
- CurrentMovingPlayerID (int) FK -> Players.ID (determines whose move is next)

Players
- ID (int) PK
- Username (nvarchar[32])
- Password (nvarchar[32]) encrypted
- MoveOrder (int) (determines the order in which players move)

ActiveGamePlayers
- ID (int) PK
- ActiveGameID (int) FK -> ActiveGames.ID
- PlayerID (int) FK -> Players.ID

ActiveGameUnits
- ID (int) PK
- ActiveGameID (int) FK -> ActiveGames.ID
- OwningPlayerID (int) FK -> Players.ID
- Type (whatever)
- Position (x,y,z, whatever)
- and so on

Thus when a player logs into the game, he (1) can see all units related to a particular active game, and (2) has access to control units from a game of which he is a part.

Share this post


Link to post
Share on other sites
Thanks for the reply. Looks like using a DB is the best way to capture and store the state of the game.

This means that each time a player does an action i'll have to update the database with the change of state.

Thanks for the tables also!

--Mike

Share this post


Link to post
Share on other sites
Quote:
Original post by silverlightDev
Hi, I am creating a turn based online strategic game similar to Empire Deluxe using Silverlight and WCF as my web server. I also have SQL and SQL Express available if I need to use a database.

Cool! [smile]
Quote:
My question is what's the best way to store the game state on the server side? Are there any good articles on this?

There's really no best way to do things. Do what makes sense, but feel free to ask questions about specific problems.
Quote:
Each time a player does a action the server will have to validate, process and update the state returning the result to the client.

Yep, unless client actions can somehow be chained together without side effects and send in one batch. Often this is not the case.
Quote:
Does the server need to pull the entire state of the game each time a player makes a move?

I'm a little unsure about the "server pulling state", because the server is either pushing state to the client or sends a response due to a client's request for state.

Ideally, the client should be as thin as possible. I should be able to play the game by just sending commands and receiving the new state, no matter what the client looks like or how it behaves. This ensures that you can rely on the integrity of the state on the server at all time, and there's always a way to synchronize the client if it falls behind.

On the other hand, you don't want to create more network traffic than necessary. Not even so much because of bandwidth, but rather because you want to provide a 'smooth' user experience. If every mouse click triggers a round trip to the server, the interface might become unresponsive and slow and might frustrate the user.

Send or request whatever is needed to have the game client accurately reflect the game's state as stored on the server.
Quote:
Obviously I shouldn’t store the entire game state in memory on the server since you never know when a player will make their next move and there could be hundreds of games running simultaneously.

No, if this is an event driven and turn based game, you may not need to explicitly keep things in memory, let the database engine take care of that.

Share this post


Link to post
Share on other sites

This topic is 2834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this