Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define DECK_SIZE 52
- #define SUIT_SIZE 4
- #define FACE_SIZE 13
- #define CARDS_IN_HAND_SIZE 5
- void shuffle(int deck[][FACE_SIZE]);
- void deal(const int deck[][FACE_SIZE], const char *face[], const char *suit[], int cardsInHand[][2]);
- void onePairCheck(int cardsInHand[][2], int size);
- void twoPairsCheck(int cardsInHand[][2], int size);
- void main(void)
- {
- srand(time(NULL));
- int deck[SUIT_SIZE][FACE_SIZE] = {0};
- const char *suit[SUIT_SIZE] = {"Hearts", "Diamonds", "Clubs", "Spades"};
- const char *face[FACE_SIZE] = {"Ace", "Deuce", "Three", "Four", "Five",
- "Six", "Seven", "Eight", "Nine", "Ten",
- "Jach", "Queen", "King"};
- int cardsInHand[CARDS_IN_HAND_SIZE][2];
- shuffle(deck);
- deal(deck, face, suit, cardsInHand);
- onePairCheck(cardsInHand, CARDS_IN_HAND_SIZE);
- twoPairsCheck(cardsInHand, CARDS_IN_HAND_SIZE);
- return;
- }
- void shuffle(int deck[][FACE_SIZE])
- {
- int row;
- int column;
- for (int card = 1; card <= DECK_SIZE; ++card)
- {
- do
- {
- row = rand() % SUIT_SIZE;
- column = rand() % FACE_SIZE;
- }while(deck[row][column] != 0);
- deck[row][column] = card;
- }
- }
- void deal(const int deck[][FACE_SIZE], const char *face[], const char *suit[],
- int cardsInHand[][2])
- {
- for (int card = 1; card <= CARDS_IN_HAND_SIZE; ++card)
- {
- int row = 0;
- int column = 0;
- for (int i = 1; i <= DECK_SIZE; i++)
- {
- if (deck[row][column] == card)
- {
- printf("%5s of %-8s\n", face[column], suit[row]);
- cardsInHand[card - 1][0] = row;
- cardsInHand[card - 1][1] = column;
- break;
- }
- if (i % FACE_SIZE == 0)
- {
- row++;
- column = 0;
- }
- else
- column++;
- }
- }
- }
- void onePairCheck(int cardsInHand[][2], int size)
- {
- for (int i = 0; i < size - 1; ++i)
- {
- for (int j = i + 1; j < size; ++j)
- {
- if (cardsInHand[i][1] == cardsInHand[j][1])
- {
- printf("\n%50s\n", "Player has one pair");
- return;
- }
- }
- }
- }
- void twoPairsCheck(int cardsInHand[][2], int size)
- {
- int pair = 0;
- int dontCheckTwice = -1;
- for (int i = 0; i < size - 1; ++i)
- {
- if (i == dontCheckTwice)
- {
- continue;
- }
- else
- {
- for (int j = i + 1; j < size; ++j)
- {
- if (cardsInHand[i][1] == cardsInHand[j][1])
- {
- pair++;
- dontCheckTwice = j;
- break;
- }
- }
- }
- if (pair == 2)
- {
- printf("\n%51s\n", "Player has two pairs");
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement