Thread: A SHOE! In a card game... ??

  1. #1

    A SHOE! In a card game... ??

    This is eluding me and I don't know why, here's what I want to do...

    I have this Baccarat simulater I'm trying to make - baccarat is very similar to blackjack so u can think of it that way if u wish.

    I want to have my program shuffle decks of cards into shoes - for those that don't know - a SHOE in a casino is usually 6-8 full decks (52 cards ea.) that are randomly shuffled together and all cards are dealt outta that shoe. I want the user to be able to select the number of decks within the SHOE from 1 to max 8. -- I will also add an infinite shoe which is basically nothing more than a seeded rand() that determines the values of the cards drawn--.

    PROBLEM:
    I just can't get my hed around the design - I don't need help coding but attacking this problem. I was thinking...

    1) using an array or enum to hold an index of the 52 cards in a deck. Or similarly, hold the suits/faces of the cards.
    2) I need another array or vector to hold the actual cards - IE this is the SHOE
    3) #PROBLEM# How do I shuffle this randomly efficiently, remember I can't use the same card twice (if I give each card an index value) or I can't use more than a certain number of Aces, Kings ( if I design to keep track of suits/faces)... If I use a rand() function how can I create it so that it says that since the value 57 has just been used it can't be used again this shuffle?

    How do I avoid getting junk values from my rand() function is the basic jist of my question - I don't want to throw out generated values from rand() b/c it's already been used...

    Pleeze help me understand how to acheive this ---

    Thanx.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Perhaps shove the the numbers which are already used into an array, and then use a do...while loop that breaks only when the generated number is not equal to any number in the array?
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    A small example generating 52 (different) random numbers (sorry it's in C). If you want 2 decks you can change the NOFDECKS define.
    Code:
    #include <stdio.h>
    #include <time.h>
    
    #define NOFDECKS 1
    
    int main()
    {
       int i;
       int r;
       int cards[52] = {0};
    
       srand(time(NULL));
    
       for(i = 0; i < NOFDECKS * 52; i++)
       {
          r = rand() % 52;
          while(cards[r] >= NOFDECKS)
             r = (r + 1) % 52;
    
          printf("%d ", r+1);
          cards[r]++;
       }
       return 0;
    }

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Look at the stl algorigthms, specifically std::random_shuffle
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    Shuffle

    a simple shuffle could look like this



    Code:
    
    for( int i = 0; i < CARDS_IN_SHOE; i++)
    {
          iRand = rand()%CARDS_IN_SHOE;
    
          //Swap cards
          temp = cards[i];
          cards[i] = cards[iRand];
          cards[iRand] = temp;
    }
    
    
    ....where cards is the actual shoe of cards...an array of int's in this case

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 05:37 PM
  2. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 07:38 AM
  3. Video card mystery
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-30-2003, 02:56 PM
  4. Replies: 2
    Last Post: 11-07-2003, 12:21 AM
  5. My Memory Game
    By jazy921 in forum C Programming
    Replies: 0
    Last Post: 05-05-2003, 05:13 PM