#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    China
    Posts
    21
    Rep Power
    0

    Designing a DB structure for a card game


    This project will be written using PHP/HTML5/CSS3/AJAX/jQuery/JS.

    I want to create a multi-player online card game website, similar to what you see in poker websites. However this game is more complex than poker, and I would like some advice as to how to set up my DB and tables.

    Let me explain the game. It's very similar to rummy. You have cards in your hand and you have to create runs or three of a kind etc in your hand, once all your cards can be used in a set, (and you have enough points) you win.

    It's a three-player game, the deck consists of 80 cards, and each player gets 20 cards. You take it in turns to pick up from the draw pile or from the previous player's discard pile (unless you can make a set of three from the other player's card, then you can take from his pile).

    At the moment I was thinking of having a table looking like this:

    game ID, p1c1, p1c2... p1c20, p1d1... p1d20, p2c1...p3d20, dc1,dc2...dc20

    [p1c1 - player 1 card 1; p1d1 - player 1 discard 1; dc1 - deck card 1]

    So 3 players, each with 20 columns, one for each card in the hand and 60 extra columns as a discard piles for the three player, as well as this, using another 20 columns for the deck cards. In total 140 columns, but I also want each player to be able to re-arrange their hand so they can more clearly see which sets they have. Do I also need an orderID column for each card? This would make the table very big! The reason it's in one line of one table is this way I can have multiple games running at once.

    Any thoughts/comments/suggestions welcome!

    -Ifor
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Location
    Saint-Petersburg, Russia
    Posts
    236
    Rep Power
    28
    Will your "multiplayer game" play only one game at a time, or many games could be run simultaneously (among several groups of people).

    UPD Ah, I see it is written in last phrase. I do not think you can make your game very scalable with such architecture. You need to choose some other technology so that current game could be held in on server continously without performing each move on database. Java, Python and perhaps some engines for PHP allow this. Also you can write your own back-end in any other language and use PHP as front-end.

    So 3 players, each with 20 columns
    It is obviously very wrong idea. You will not be able to easily move card between columns.

    This could be stored in the table with only 3 columns:
    (player_id, card_id, order_in_hand)
    here would be 60 lines in such table for your case.
    Last edited by rodiongork; December 4th, 2013 at 10:58 PM.
    CodeAbbey - programming problems for novice coders
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    China
    Posts
    21
    Rep Power
    0
    Originally Posted by rodiongork
    Will your "multiplayer game" play only one game at a time, or many games could be run simultaneously (among several groups of people).

    UPD Ah, I see it is written in last phrase. I do not think you can make your game very scalable with such architecture. You need to choose some other technology so that current game could be held in on server continously without performing each move on database. Java, Python and perhaps some engines for PHP allow this. Also you can write your own back-end in any other language and use PHP as front-end.


    It is obviously very wrong idea. You will not be able to easily move card between columns.

    This could be stored in the table with only 3 columns:
    (player_id, card_id, order_in_hand)
    here would be 60 lines in such table for your case.
    Yeah that's what I was worried about. The other way I thought of doing it was maybe storing each players' hand in a JS array? But not sure about security and sharing the arrays with the other players.

    I have no experience in using Java or Python, which is why I was hoping I could use mysql and php
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    China
    Posts
    21
    Rep Power
    0
    Anyone else have any insights?
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Location
    Saint-Petersburg, Russia
    Posts
    236
    Rep Power
    28
    hand in a JS array?
    Yes, it is possible, however it has two great drawbacks:
    - if user closes the page the game is frustrated for all other players (even if he reopens it later);
    - anyone can edit his hand during play, so you should expect at least five aces in your deck, ha-ha.

    Why do not you want the proposed table structure with 3-4 columns and single row per single card?

    And well, about "I do not know Java or Python": imagine you want to build a ladder or a table. And you tell "I only know how to hold an axe, I never know anything about hammer, nails, saw and screwdriver... Perhaps I could do this with only an axe?"

    Well - as a matter of fact you really could - but it may take more efforts than learning to use more suitable instrument.
    CodeAbbey - programming problems for novice coders
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    China
    Posts
    21
    Rep Power
    0
    Originally Posted by rodiongork
    Yes, it is possible, however it has two great drawbacks:
    - if user closes the page the game is frustrated for all other players (even if he reopens it later);
    - anyone can edit his hand during play, so you should expect at least five aces in your deck, ha-ha.

    Why do not you want the proposed table structure with 3-4 columns and single row per single card?

    And well, about "I do not know Java or Python": imagine you want to build a ladder or a table. And you tell "I only know how to hold an axe, I never know anything about hammer, nails, saw and screwdriver... Perhaps I could do this with only an axe?"

    Well - as a matter of fact you really could - but it may take more efforts than learning to use more suitable instrument.
    \

    Haha, I guess you're right.

    This structure was the only way I could think of that could keep track of where every card it at one time. If a card is discarded the cardID should move to another column, then if the next player picks it up, then the cardID is moved again to a new cell. I also need to know if a player has two of the same cards, if so, they can pick up a third card of the same suit and number from any player, not just the next player along.

    I'm halfway through writing a website on how to play this game, maybe it would be easier if you had a look: aidesigns-ys . com / dev / paohuzi

    Thanks again for your help.

    -Ifor

IMN logo majestic logo threadwatch logo seochat tools logo