rendered paste body//bridge.cpp
#include<iostream>
using namespace std;
const int hand=13;
const int deckSize=52;
int shuffle(int a[ ]) {
srand(time(NULL));
for(int l=0; l<deckSize; l++) {
int m= rand() % (deckSize-l);
int tmp=a[l];
a[l]=a[l+m];
a[l+m]=tmp;
}
}
string convertRank(int a){
string rank;
switch(a % 13) {
case 0:
rank = "A ";
break;
case 1:
rank = "2 ";
break;
case 2:
rank = "3 ";
break;
case 3:
rank = "4 ";
break;
case 4:
rank = "5 ";
break;
case 5:
rank = "6 ";
break;
case 6:
rank = "7 ";
break;
case 7:
rank = "8 ";
break;
case 8:
rank = "9 ";
break;
case 9:
rank = "10 ";
break;
case 10:
rank = "J ";
break;
case 11:
rank = "Q ";
break;
case 12:
rank = "K ";
break;
}
return rank;
}
void intoSuit(int a[ ]) {
string clubs, spades, hearts, diamonds;
spades = " ";
clubs = " ";
hearts = " ";
diamonds = " ";
for(int n=0;n<hand;n++){
if (a[n]<13) {
spades = spades + convertRank(a[n]);;
}
else if (a[n]>38) {
clubs = clubs + convertRank(a[n]);
}
else if ((a[n]>12) && (a[n]<26)) {
hearts = hearts + convertRank(a[n]);
}
else if ((a[n]>25) && (a[n]<39)) {
diamonds = diamonds + convertRank(a[n]);
}
}
cout << "\nSpades: " << spades << endl;
cout << "Hearts: " << hearts << endl;
cout << "Clubs: " << clubs << endl;
cout << "Diamonds: " << diamonds << endl;
}
int count(int a[ ]){
int total=0;
for(int u=0; u<hand; u++) {
if (a[u] % 13 == 0) {
total = total + 4;
}
else if (a[u] % 13 == 10) {
total = total + 1;
}
else if (a[u] % 13 == 11) {
total = total + 2;
}
else if (a[u] % 13 == 12) {
total = total + 3;
}
}
return total;
}
void defineWinner(int w, int x, int y, int z){
if ((w > x) && (w > y) && (w > z)){
cout << "Hand 1 is the winner!" << endl;
}
else if ((x > w) && (x > y) && (x > z)){
cout << "Hand 2 is the winner!" << endl;
}
else if ((y > w) && (y > w) && (y > z)){
cout << "Hand 3 is the winner!" << endl;
}
else if ((z > w) && (z > x) && (z > y)){
cout << "Hand 4 is the winner!" << endl;
}
else {
cout << "There is no clear winner please try again" << endl;
}
}
int main( ) {
int hand1[hand], hand2[hand], hand3[hand], hand4[hand];
int hand1total=0, hand2total=0, hand3total=0, hand4total=0;
int deck[deckSize] = { 0,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 };
shuffle(deck);
int q=0;
for(int n=0;n<hand;n++){
hand1[n] = deck[n];
}
for(int n=hand;n<(hand * 2);n++){
hand2[q] = deck[n];
q++;
}
q=0;
for(int n=(hand * 2);n<(hand * 3);n++){
hand3[q] = deck[n];
q++;
}
q=0;
for(int n=(hand * 3);n<(hand * 4);n++){
hand4[q] = deck[n];
q++;
}
//output
cout << "Hand 1: " << endl;
intoSuit(hand1);
hand1total = count(hand1);
cout << "Hand 1 total is: " << hand1total << " points." << endl;
cout << "\nHand 2: " << endl;
intoSuit(hand2);
hand2total = count(hand2);
cout << "Hand 2 total is: " << hand2total << " points." << endl;
cout << "\nHand 3: " << endl;
intoSuit(hand3);
hand3total = count(hand3);
cout << "Hand 3 total is: " << hand3total << " points." << endl;
cout << "\nHand 4: " << endl;
intoSuit(hand4);
hand4total = count(hand4);
cout << "Hand 4 total is: " << hand4total << " points." << endl;
defineWinner(hand1total,hand2total,hand3total,hand4total);
system("pause");
return 0;
}