-11

I have an assignment due in my computer science class (I posted this question a couple weeks ago but the way it was explained doesn't fit the program I'm supposed to do). I already have a program that shuffles and deals a deck right here.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void shuffle( int [][ 13 ] );
void deal ( const int[][ 13 ], const char *[], const char *[] );


 int main()
 {
  const char *suit[4] ={"Hearts","Diamonds","Clubs","Spades"};
    const char *face[13] ={"Ace", "Duece", "Three", "Four", "Five", "Six", 
    "Seven", "Eight","Nine", "Ten", "Jack", "Queen", "King"};
    int deck[4][13] = {0};
    int row, column, card = 1;


    for( row = 0; row <= 3; row++ )
    {
        for(column = 0; column <= 12; column++)
            {
            deck[row][column] = card;
            card++;
            }
    }

        srand(time(0));
        shuffle(deck);
        deal(deck, face, suit);
    return 0;
 }

 void shuffle( int wDeck[][13] )
 {
    int row, column, randomColumn, randomRow, card = 1, counter1, counter2, hold;




    for( counter1 = 0; counter1 <= 3; counter1++) 
    {
        for(counter2 = 0; counter2 <= 12; counter2++)
            {
                randomColumn = rand() % 13;
                randomRow = rand() % 4;

                    hold = wDeck[counter1][counter2];
                    wDeck[counter1][counter2] = wDeck[randomRow][randomColumn]; 
                    wDeck[randomRow][randomColumn] = hold;
            }
       }
    }

 void deal( const int wDeck[][13], const char *wFace[], const char *wSuit[] )
{
  int card, row, column;

        for ( card = 1; card <= 52; card++ )
            for (row = 0; row <= 3; row++ )
                for ( column = 0; column <= 12; column++ )
                    if( wDeck[row][column] == card )
                    {
                    printf("%5s of %-8s%c",wFace[ column ], wSuit[row], card % 2 == 0 ? '\n' : '\t');
                    break;
                    }
}

I'm supposed to modify the deal function to deal a 5 card poker hand, and then later check to see what "rank" poker hand they have(two of a kind, flush). My teacher mentioned creating a separate double scripted array to do this but I could do it a different way. The problem is, I have to use the current deck/shuffle setup to do it. Could anyone explain how to do this? It's okay if it's inefficient, as long as it works.

syb0rg
  • 8,057
  • 9
  • 41
  • 81
  • 4
    So what's the problem? You create an array of cards, and then use a function (or bunch of functions) to find the rank. – lxop Apr 19 '13 at 01:46
  • I can't figure out how to assign the five cards to an array. I can figure out how to find the rank, but first I need to have the 5 card hand, which I cannot for the life of me comprehend. – user2297456 Apr 19 '13 at 13:22

1 Answers1

1

With the existing deal prototype, there is no way to return information from it - it has no return value and all the arguments are const. Since the deck has already been shuffled (by shuffle()), I assume the idea is for the deal function to look at the first five cards in the deck array, and find the rank of them. That can either be done entirely within the deal function, or (better), by calling a int rank(int hand[5]) function from within the deal function.

lxop
  • 7,596
  • 3
  • 27
  • 42