0

ok.. so im trying to make a function to find a par of cards with the same suit value for a game of 5 card poker. Here is what i have so far:

my main:

int main (void)
{
	/* initialize suit array */
	const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"};

	/* initialize face array */
	const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight",
		"Nine", "Ten", "Jack", "Queen", "King"};

	Card hand1[5];

	/* initalize deck array */
	int deck[4][13] = {0};

	srand ((unsigned) time (NULL)); /* see random-number generator */

	shuffle (deck);
	deal (deck, face, suit, hand1);

	return 0;
}

my functions:

#include "function.h"

/* shuffle cards in deck */

void shuffle (int wDeck[][13])
{
	int row = 0;    /* row number */
	int column = 0; /*column number */
	int card = 0;   /* card counter */

	/* for each of the 52 cards, choose slot of deck randomly */
	for (card = 1; card <= 52; card++)
	{
		/* choose new random location until unoccupied slot found */
		do
		{
			row = rand () % 4;
			column = rand () % 13;
		} while (wDeck[row][column] != 0);

		/* place card number in chosen slot of deck */
		wDeck[row][column] = card;
	}
}

/* deal cards in deck */
void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[], Card hand[])
{
	int row = 0;    /* row number */
	int column = 0; /*column number */
	int card = 0;   /* card counter */
 
	/* deal each of the 52 cards */
	for (card = 1; card <= 5; card++)
	{
		/* loop through rows of wDeck */
		for (row = 0; row <= 3; row++)
		{
			/* loop through columns of wDeck for current row */
			for (column = 0; column <= 12; column++)
			{
				/* if slot contains current card, display card */
				if (wDeck[row][column] == card)
				{
					printf ("%5s of %-8s%c", wFace[column], wSuit[row], card % 2 == 0 ? '\n' : '\t');
					hand[card-1].card_num = card;
					hand[card-1].face = column;
					hand[card-1].suit = row;
				}
			}
		}
	}
}

and the header file:

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

typedef struct card
{
	int card_num;
	int suit;
	int face;
} Card;

void shuffle (int wDeck[][13]);
void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[], Card hand[]);

ANY help is appreciated.

2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by dimmu1
0

What problem are you having?

i have no idea where how to even start writing the function. it needs to detect an N-of-a-kind basically. my code runs and there is no error on that part.

0

You really just need to look for duplicates. For any card in the hand that has more than one instance, maintain a count along with the value of the card. If the count is 2 you have a pair, 3 you have three of a kind, etc...

0

You really just need to look for duplicates. For any card in the hand that has more than one instance, maintain a count along with the value of the card. If the count is 2 you have a pair, 3 you have three of a kind, etc...

i know what the basic idea is. i do not know how to implement that with the struct and other stuff i have in my code. we have to use the struct. its part of the grade..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.