December 4th, 2013, 10:52 PM
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!
December 4th, 2013, 11:54 PM
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.
Last edited by rodiongork; December 4th, 2013 at 11:58 PM.
December 5th, 2013, 12:20 AM
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.
Originally Posted by rodiongork
I have no experience in using Java or Python, which is why I was hoping I could use mysql and php
December 7th, 2013, 11:51 PM
Anyone else have any insights?
December 8th, 2013, 12:11 AM
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.
December 8th, 2013, 12:19 AM
Originally Posted by rodiongork
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.