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
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
string cards[52]={"SA", "SK", "SQ", "SJ", "ST", "S9", "S8", "S7", "S6", "S5", "S4", "S3", "S2",
"HA", "HK", "HQ", "HJ", "HT", "H9", "H8", "H7", "H6", "H5", "H4", "H3", "H2",
"DA", "DK", "DQ", "DJ", "DT", "D9", "D8", "D7", "D6", "D5", "D4", "D3", "D2",
"CA", "CK", "CQ", "CJ", "CT", "C9", "C8", "C7", "C6", "C5", "C4", "C3", "C2"};
srand ( unsigned (time(0) ) );
vector<string> deck;
for (int i=0; i<52; i++)
{
deck.push_back(cards[i]);
}
bool programactive=true;
while (programactive)
{
cout << "press Q to quit or S to simulate" << endl;
string command;
cin >> command;
if (command=="Q" || command=="q")
{
programactive=false;
}
else if (command=="S" || command=="s")
{
cout << "enter min-max HCP" << endl;
int minHCP, maxHCP;
cin >> minHCP;
cin >> maxHCP;
/*cout << "enter min-max spades" << endl; // for suit distribution later
int minSpades, maxSpades;
cin >> minSpades;
cin >> maxSpades;
cout << "enter min-max hearts" << endl;
int minHearts, maxHearts;
cin >> minHearts;
cin >> maxHearts;
cout << "enter min-max diamonds" << endl;
int minDiamonds, maxDiamonds;
cin >> minDiamonds;
cin >> maxDiamonds;
cout << "enter min-max Clubs" << endl;
int minClubs, maxClubs;
cin >> minClubs;
cin >> maxClubs;*/
cout << "how many hands do you want to test?" << endl;
int Hands;
cin >> Hands;
int totalHCP=0;
int qualifiedHands=0;
while (qualifiedHands < Hands)
{
int HCP=0;
int spades=0;
int hearts=0;
int diamonds=0;
int clubs=0;
std::random_shuffle(deck.begin(),deck.end());
for (int i=0; i<13; i++)
{
if (deck[i][1]=="A") // this is where the first error is, I need to extract the second character from each element
{
HCP+=4;
}
else if (deck[i][1]=="K")
{
HCP+=3;
}
else if (deck[i][1]=="Q")
{
HCP+=2;
}
else if (deck[i][1]=="J")
{
HCP++;
}
}
if (HCP>=minHCP && HCP<=maxHCP)
{
totalHCP+=HCP;
qualifiedHands++;
}
}
double averageHCP;
averageHCP=totalHCP/Hands;
cout << averageHCP << endl;
}
}
return 0;
}
|