1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
const int ROWS(4),
COLS(13),
NUM_CARDS(52);
string suit[] = {"Clubs", "Diamond", "Hearts", "Spades"};
string face[] = {"Ace", "Duece", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King"};
int deck[ROWS][COLS]; //declared globally, initialized to 0
void shuffleDeck(int shuffleArray[][COLS], int);
void dealHands(int dealArray[][COLS], int);
bool found;
int main()
{
int pos(1);
for (int r=0; ! found && r !=ROWS; r++) //setting deck[] positions to 1-52
{
for(int c = 0; ! found && c !=COLS; c++)
{
deck[r][c] = pos++;
}
}
srand(time(NULL)); //used for random number generator to shuffle
shuffleDeck(deck, ROWS);//shuffle deck
for (int n=0; n <= NUM_CARDS; n++) //display shuffled deck
{
found = false;
for (int r=0; !found && r !=ROWS; r++)
{
for(int c=0; !found && c !=COLS; c++)
{
if (deck[r][c] == n)
{
cout << deck[r][c] << " " << face[c] << " of " << suit[r] << endl;
found=true;
}
}
}
}
//display hands
cout << "***** HAND 1 *****" << endl;
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 1 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 3 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 5 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 7 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 9 )
cout << face[c] << " of " << suit[r] << endl;
}
cout << "***** HAND 2 *****" << endl;
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 2 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 4 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 6 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 8 )
cout << face[c] << " of " << suit[r] << endl;
}
for (int r=0; r < ROWS; r++)
for (int c=0; c<COLS; c++)
{
if (deck[r][c] == 10 )
cout << face[c] << " of " << suit[r] << endl;
}
}//end main
void shuffleDeck(int shuffleArray[][COLS], int numRows)
{
for (int n=0; n <= NUM_CARDS; n++)
{
for (int row = 0; row < numRows; row++)
{
for (int col=0; col < COLS; col++)
{
if (deck[row][col] == n)
{
int temp(0);
int cardvalue = rand() % 13 ;
int cardsuit = rand() % 4 ;
temp = deck[row][col];
deck[row][col] = shuffleArray[cardsuit][cardvalue];
shuffleArray[cardsuit][cardvalue] = temp;
}
}
}
}
}//end shuffleDeck
|