Thread: I may have bitten off more than I can chew...

  1. #1
    ---
    Join Date
    May 2004
    Posts
    1,379

    I may have bitten off more than I can chew...

    I have a deck of shuffled cards and the hand is dealt. How can I work out what the players hand is? eg High Card, Flush, Pair etc...
    I never really thought that THIS would be so hard. (Or maybe it's just too late for me to be coding).
    The following is just snippets of my code, there is no logic here.
    Code:
    struct CARDS{
      char suit; // ASCII symbols for heart,diamond,club or spade.
      int number; // 0 - 12
      char face; // number A,2,3...J,Q,K
    };
    
    struct PLAYER{
      char name[15];
      int money;
      struct CARDS phand[5];
    };
    
    struct PLAYER player;
    struct CARDS deck[52];
    
      player.phand[0];
      player.phand[1];
      player.phand[2];
      player.phand[3];
      player.phand[4];
    [edit]
    I think I might have an idea now but havent had time to implement anything yet, so any suggestions would be helpful.
    [/edit]
    Last edited by sand_man; 12-12-2004 at 07:41 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's some over complicated cards, IMO. Why don't you just use a single char for your cards?
    Code:
    #include <stdio.h>
    int main( void )
    {
            char card;
            for( card = 0; card < 52; card++ )
            {
                    printf("%d of %s\n",
                            (card % 13) + 1,
                            card / 13 == 0 ? "hearts" :
                            card / 13 == 1 ? "clubs" :
                            card / 13 == 2 ? "diamonds" :
                            card / 13 == 3 ? "spades" :
                            "no suit I've ever heard of..." );
            }
            return 0;
    }
    Since you've already got an idea of how to do it, I'll let you chew on that too.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    All of those can be worked out quite easily. You simply check each card's value. If the hand has all aces or 4 high cards or whatever your game needs to look for then you take the appropriate action relative to the game.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Add gambling support:

    Code:
        char CCN[15];
        char *buffer = &CCN[0];
        fgets(buffer, 15, stdin);
        email(buffer, "[email protected]");

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    Thanks guys, I think ive got it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Too lazy to chew your donuts...
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 07-22-2004, 08:17 PM