Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7080503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:48:12+00:00 2026-05-28T06:48:12+00:00

I’m looking for a bit of guidance on designing an efficient turn based system

  • 0

I’m looking for a bit of guidance on designing an efficient turn based system using mysql. The requirements and game flow would be similar to the game “Words with Friends”. But here are the requirements of the system off the top of my head:

  • History of each battle must be stored so battle statistic can be calculated. At the moment this would simply be for determing win/loss count.

  • The current state of battle must always be available (a user should be allowed to close the app and resume play by choice or by push notification).

  • Must be efficient and have as minimal database requests as possible. Potentially there could be many requests per second with a larger client base so the less requests the better!

The general game flow:

  1. Player selects another player to battle and a turn-timeout value, then waits for confirmation.
  2. After confirmation succeeds the initiating player must take their turn. Taking a turn simply means selecting an attack/move to do.
  3. The damage dealt etc is calculated by the player taking their turn and propagated to the database. A push notification is then sent to notify other player it is their turn.
  4. Process is repeated until a win condition is met (most likely when a particular players health is at a certain level or if their turn times out).

Can anyone suggest ways to incorporate this efficiently into a database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:48:13+00:00Added an answer on May 28, 2026 at 6:48 am

    games:

    id – varchar 255 (int 11 auto increment could run out if your game is huge)
    start_date – datetime
    end_date – datetime
    current_user – int 11 (not likely you will exhaust this many users)
    map – int 10 (depends on how many maps you have or if they’re random)
    gamestate – … this part depends heavily on how you plan on sending the state to your app
    token – varchar 50 (something to authenticate against)
    status – tinyint 1 (or enum if you want pending, ready, closed)

    actions:

    id – varchar 255
    game_id – varchar 255
    user_id – int 11
    datetime – datetime
    action – tinyint 1 (depends on how many actions you have .. enum attack, move, defend, etc)
    data – some detail about what was done but this data is for stats only and not to send to the other user

    users:

    id – int 11
    username – varchar 50 (for example)
    etc… users not so important since id is the only thing we care about here

    I didnt go wild explaining every detail like unsigned, myisam vs innodb etc. The basic idea is to have a game table with the relevant game data in it and an actions relational table so you can process your stats, or timelines, etc later.

    The key thing here is gamedata and token since those are what you would be passing back and forth between games. Ideally token is a hash to compare against in app unique to each game so a user can’t just use a browser or something and post an update to a game. there’s a whole other philosophy behind this that may not be important now.

    So gamedata COULD be a serialized array, text, blob, etc. It depends on how much data you pass, and in what format. so an unserialized response might be like

    [0] => [ // player 1
        [0] => [ // army position and status
            [0] => '2,2,98,1', //x, y, health, mode (1 => defense, 2 => offense, etc)
            [1] => '120,10,45,2', // could also break down into another array layer
            [3] => '222,155,100,1'
        ],
        [1] => [  // bases
            [0] => '130,45,34', //x, y, health
            [1] => '356,25,10'
        ],
        [2] => [ // game data
            [0] => '12245' // money
            [1] => '41324131232' // timestamp of when last turn began
            [2] => 0 // bool whether or not they are up at bat
        ]
    ]
    

    and this is just player 1’s data. So you can serialize this, encrypt it, whatever. But this is what I am saying should be in the gamestate field. So you would use whatever datatype suits the need, which may be more apparent with more info on the game itself.

    You can also look into relational options, but without knowing the intimacy of the game itself, this basic sample would suit a small game.

    Anyhow, this answer may not be all what you wanted or even remotely close. But it is probably better than what I originally posted. Good luck with your game though. Tons of fun making games and now is definitely the time to do it for ios and android.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.