Jump to content

Recommended Posts

 

I am wanting to create a little blackjack game (text for now) for fun but I can't seem to figure out how I should store the cards.

 

Total of 52 cards (right? can't remember lol)

 

Values: 2 through 10, Jack, Queen, King and Ace

4 Suites: Club, Diamond, Hearts and Spades

 

I will also want to do 7 decks but for now I think I'll stick to working out with one.

 

I am also not sure how I would handle the values of the face cards (which of course are 10) and the ace being either 1 or 11.

 

Would a multi-dimension array work? $cards = array("S" => array(2, 3, 4, 5....), "C" => array(2, 3, 4, 5));

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/57344-blackjack/
Share on other sites

I don't fully recall how the game is played, but here's how I would go about this:

 

Have a Deck object, 2 Hand objects, 2 Player objects, Card objects (have the Deck create those on demand--you don't want 52 objects when you might only need 15 or so) a GamePlay object and a Table object. GamePlay Player object calculates the maximum score of a Player based on it's Hand and the Table. For an ace, it assumes 11, if the total score's over 21, it recalculates using 1.

 

As for generating Card objects, an array is a good source. The Deck can hold an array of Card-id's.

 

array('S_J' = >array('suite' => 'Spades', 'value' = > 'J'), 'C_10' => array('suite' => 'Club', 'value' = > '10'), etc...

 

That way it can easily shuffle a deck, and keep track of Cards dealt. Remember, the actual scores they represent is encapsulated by the GamePlay object. That way, if you would want to change the scoring, you only change the GamePlay object.

Link to comment
https://forums.phpfreaks.com/topic/57344-blackjack/#findComment-283798
Share on other sites

It's not clear why the hand class is needed?  What's the benefit delegating some of the player's responsibility to a hand class?  Likewise the table may not be necessary, but I could see that being potentially useful as a database of objects "in the game" which could be interpreted by the AI.

Link to comment
https://forums.phpfreaks.com/topic/57344-blackjack/#findComment-284660
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.