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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
int point[52];
int a[52];
int scoring(int a, int b, int c, int d, int e)
{
int R[5];
int S[5], x[5];
x[0]=a; x[1]=b; x[2]=c; x[3]=d; x[4]=e;
for (int o=0; o<5; o++)
{
R[o] = x[o]%13;
S[o] = x[o]/13;
}
// Sort the R array
bool swapped = false;
do
{
// 1 pass of the bubble sort
swapped = false;
for(int o=0; o<4; o++)
{
if(R[o] > R[o+1])
{
int temp = R[o];
R[o] = R[o+1];
R[o+1] = temp;
swapped = true;
}
}
}
while(swapped == true);
int scoring= 0;
// Check for a straight:
if(R[1]==R[0]+1 && R[2]==R[1]+1 && R[3]==R[2]+1 && R[4]==R[3]+1)
{
cout << "You got a Straight" << endl;
scoring=(scoring+19);
}
else
{
scoring=(scoring+0);
}
// Check first 5 cards for any pair
if(R[0] == R[1] || R[1]==R[2] || R[2]==R[3] || R[3]==R[4])
{
// check for twopair
if(R[0]==R[1]&&R[2]==R[3]||R[1]==R[2]&&R[3]==R[4]||R[0]==R[1]&&R[3]==R[4])
{
cout << "You got a Twopair" << endl;
scoring=(scoring+17);
}
// check for 3 of a kind
if(R[0] == R[1] == R[2] || R[1] == R[2] == R[3] || R[2] == R[3] == R[4])
{
cout << "You got a 3 of a kind" << endl;
scoring=(scoring+18);
}
// Check for 4 of a kind
if(R[0] == R[1] == R[2] == R[3] || R[1] == R[2] == R[3] == R[4])
{
cout << "You got a 4 of a kind" << endl;
scoring=(scoring+22);
}
else
{
cout << "You got a Pair" << endl;
scoring=(scoring+16);
}
}
else
{
scoring=(scoring+0);
}
// Check for a flush (all the same suit)
if(S[0] == S[1] && S[1]==S[2] && S[2]==S[3] && S[3]==S[4])
{
cout << "You got a Flush" << endl;
scoring=(scoring+20);
}
else
{
scoring=(scoring+0);
}
// Check for straight flush
if(S[0] == S[1] && S[1]==S[2] && S[2]==S[3] && S[3]==S[4])
{
if(R[1]==R[0]+1 && R[2]==R[1]+1 && R[3]==R[2]+1 && R[4]==R[3]+1)
{
cout << "You got a Straight Flush" << endl;
scoring=(scoring+23);
}
else
{
scoring=(scoring+0);
}
}
// check for royal flush
// Check for full house
if(R[0] == R[1] == R[2] && R[3] == R[4] || R[0] == R[1] && R[2] == R[3] == R[4])
{
cout << "You got a Full House" << endl;
scoring = (scoring + 21);
}
else
{
scoring=scoring+0;
}
//check for the highest score
}
int main()
{
srand(time(0));
int deck[52];
int i;
string suitnames[4]={"spades", "hearts", "clubs", "diamonds"};
string ranknames[13]={"ace", "king", "queen", "jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"};
// create a new deck, with cards in order, but unique
for(i=0; i<52; i++)
{
deck[i] = i;
}
// shuffle the deck:
for(i=0; i<52; i++)
{
// generate a random index to swap with the card at index i.
int j = rand() % 52;
int temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
// print all the cards
for(i=0; i<52; i++)
{
int suitnumber = deck[i] / 13; // 0 - 3
int rank = deck[i] % 13;
cout << ranknames[rank] << " of " << suitnames[suitnumber]<< "\n";
}
cout << endl;
for(i=0; i<52; i++)
{
int temp = deck[i];
deck[i]=a[i];
a[i]=temp;
}
int f;
cout << "your card :"<< endl;
f=0;
while(f<20)
{
cout << f << ". ";
int suitnumber = a[f] / 13; // 0 - 3
int rank = a[f] % 13;
cout << ranknames[rank] << " of " << suitnames[suitnumber]<< "\n";
f=f+4;
}
int n;
cout << "do you want to replace your card ? [type 1 for yes, 0 for no]" << endl;
cin >> n;
switch (n)
{
case 1:
cout << "which card do you want to replace?[insert the number]";
int o;
cin >> o;
int suitnumber = a[o] / 13; // 0 - 3
int rank = a[o] % 13;
cout << "you want to replace " << ranknames[rank] << " of " << suitnames[suitnumber]<< "\n";
int temp = a[o];
a[o] = a[20];
a[20] = temp;
cout <<"your card now:" << endl;
o=0;
while(o<20)
{
int suitnumber = a[o] / 13; // 0 - 3
int rank = a[o] % 13;
cout << ranknames[rank] << " of " << suitnames[suitnumber]<< "\n";
o=o+4;
}
}
//sorty(a[0], a[4], a[8], a[12], a[16]);
cout << "your score : " << scoring(a[0], a[4], a[8], a[12], a[16]) << endl << endl;
//sorty(a[1], a[5], a[9], a[13], a[17]);
cout << "score P2 :"<< scoring(a[1], a[5], a[9], a[13], a[17]) << endl << endl;
//sorty(a[2], a[6], a[10], a[14], a[18]);
cout << "score P3 :"<< scoring(a[2], a[6], a[10], a[14], a[18]) << endl << endl;
//sorty(a[3], a[7], a[11], a[15], a[19]);
cout << "score P4 :"<< scoring(a[3], a[7], a[11], a[15], a[19]) << endl << endl;
return 0;
}
|