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
|
//Strategy Tables
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
enum decision{BLACKJACK,HIT,STAND,DOUBLE,SPLIT};
class Strategy{
public:
vector< vector<decision> > Pair;
vector< vector<decision> > Ace;
vector< vector<decision> > Score;
Strategy();
void fillBasic();
};
Strategy::Strategy() :Pair(11, vector<decision>(11)),
Ace(11, vector<decision>(11)),
Score(22, vector<decision>(11)){} //I looked up how to do this
//but I sure dont understand it
//It breaks if I do it inside the constructor
void Strategy::fillBasic(){ //This function fills these two dimensional arrays
//with the enums taken from this strategy chart
//http://www.blackjackclassroom.com/wp-content/uploads/2009/12/blackjack-basic-strategy.png
Pair[2][2] = Pair[2][3] = Pair[2][4] = Pair[2][5] = Pair[2][6] =
Pair[2][7] = Pair[3][2] = Pair[3][3] = Pair[3][4] = Pair[3][5] =
Pair[3][6] = Pair[3][7] = Pair[4][5] = Pair[4][6] = Pair[6][2] =
Pair[6][3] = Pair[6][4] = Pair[6][5] = Pair[6][6] = Pair[7][2] =
Pair[7][3] = Pair[7][4] = Pair[7][5] = Pair[7][6] = Pair[7][7] =
Pair[9][2] = Pair[9][3] = Pair[9][4] = Pair[9][5] = Pair[9][6] =
Pair[9][8] = Pair[9][9] = Pair[1][2] = Pair[1][3] = Pair[1][4] =
Pair[1][5] = Pair[1][6] = Pair[1][7] = Pair[1][8] = Pair[1][9] =
Pair[1][10] = Pair[1][1] = Pair[8][2] = Pair[8][3] = Pair[8][4] = Pair[8][5] =
Pair[8][6] = Pair[8][7] = Pair[8][8] = Pair[8][9] = Pair[8][10] = Pair[8][1] = SPLIT;
Pair[2][8] = Pair[2][9] = Pair[2][10] = Pair[2][1] = Pair[3][8] =
Pair[3][9] = Pair[3][10] = Pair[3][1] = Pair[4][2] = Pair[4][3] =
Pair[4][4] = Pair[4][7] = Pair[4][8] = Pair[4][9] = Pair[4][10] =
Pair[4][1] = Pair[5][10] = Pair[5][1] = Pair[6][7] = Pair[6][8] =
Pair[6][9] = Pair[6][10] = Pair[6][1] = Pair[7][8] = Pair[7][9] =
Pair[7][10] = Pair[7][1] = HIT;
Pair[9][7] = Pair[9][10] = Pair[9][1] = Pair[10][2] = Pair[10][3] =
Pair[10][4] = Pair[10][5] = Pair[10][6] = Pair[10][7] = Pair[10][8] =
Pair[10][9] = Pair[10][10] = Pair[10][1] = STAND;
Pair[5][2] = Pair[5][3] = Pair[5][4] = Pair[5][5] = Pair[5][6] = Pair[5][7] =
Pair[5][8] = Pair[5][9] = DOUBLE;
for (int i = 0; i < 11; i++) //fill with hit then set
for (int j = 0; j < 11; j++) //just the doubles and stands
Ace[i][j] = HIT;
Ace[2][5] = Ace[2][6] = Ace[3][5] = Ace[3][6] = Ace[4][4] = Ace[4][5] =
Ace[4][6] = Ace[5][4] = Ace[5][5] = Ace[5][6] = Ace[6][3] = Ace[6][4] =
Ace[6][5] = Ace[6][6] = Ace[7][3] = Ace[7][4] = Ace[7][5] = Ace[7][6] = DOUBLE;
Ace[7][2] = Ace[7][7] = Ace[7][8] = STAND;
for (int i = 8; i < 10; i++)
for (int j = 0; j < 11; j++) //Stand on 19 or better
Ace[i][j] = STAND;
for (int j = 0; j < 11; j++)
Ace[10][j] = BLACKJACK;
for (int i = 0; i <= 8; i++){
for (int j = 0; j < 11; j++)
Score[i][j] = HIT;
}
for (int i = 17; i <= 21; i++){
for (int j = 0; j < 11; j++)
Score[i][j] = STAND;
}
Score[9][2] = Score[9][7] = Score[9][8] = Score[9][9] = Score[9][10] = Score[9][1] =
Score[9][3] = Score[9][4] = Score[9][5] = Score[9][6] = Score[10][2] =
Score[10][3] = Score[10][4] = Score[10][5] = Score[10][6] = Score[10][7] =
Score[10][8] = Score[10][9] = Score[11][2] = Score[11][3] = Score[11][4] =
Score[11][5] = Score[11][6] = Score[11][7] = Score[11][8] = Score[11][9] =
Score[11][10] = DOUBLE;
Score[12][2] = Score[12][3] = Score[12][7] = Score[12][8] = Score[12][9] = Score[12][10] =
Score[12][1] = Score[13][7] = Score[13][8] = Score[13][9] = Score[13][10] = Score[13][1] =
Score[14][7] = Score[14][8] = Score[14][9] = Score[14][10] = Score[14][1] =
Score[15][7] = Score[15][8] = Score[15][9] = Score[15][10] = Score[15][1] =
Score[16][7] = Score[16][8] = Score[16][9] = Score[16][10] = Score[16][1] = HIT;
Score[13][2] = Score[13][3] = Score[13][4] = Score[13][5] = Score[13][6] =
Score[14][2] = Score[14][3] = Score[14][4] = Score[14][5] = Score[14][6] =
Score[15][2] = Score[15][3] = Score[15][4] = Score[15][5] = Score[15][6] =
Score[16][2] = Score[16][3] = Score[16][4] = Score[16][5] = Score[16][6] = STAND;
}
int main(){
string dec[] = { "BJ", "HT", "ST", "DB", "SP" };
Strategy basic;
basic.fillBasic();
// print out the tables
// to find any errors
cout << setw(30) << right << "Pairs- Dealer Card\n\n";
cout << " ";
for (int i = 1; i <= 10; i++)
cout << setw(5) << right << i;
cout << endl;
cout << setfill('-') << setw(60) << '-' << endl;
cout << setfill(' ');
for (int i = 1; i <= 10; i++){
cout << setw(2) << right << i << ','
<< setw(2) << right << i << '|';
for (int j = 1; j <= 10; j++){
cout << setw(5) << right << dec[basic.Pair[i][j]];
}
cout << endl << " |"<<endl;
}
cout << setw(30) << right << "Ace Combos- Dealer Card\n\n";
cout << " ";
for (int i = 1; i <= 10; i++)
cout << setw(5) << right << i;
cout << endl;
cout << setfill('-') << setw(60) << '-' << endl;
cout << setfill(' ');
for (int i = 2; i <= 10; i++){
cout << setw(2) << right << 'A' << ','
<< setw(2) << right << i << '|';
for (int j = 1; j <= 10; j++){
cout << setw(5) << right << dec[basic.Ace[i][j]];
}
cout << endl << " |" << endl;
}
cout << setw(30) << right << "Score - Dealer Card\n\n";
cout << " ";
for (int i = 1; i <= 10; i++)
cout << setw(5) << right << i;
cout << endl;
cout << setfill('-') << setw(60) << '-' << endl;
cout << setfill(' ');
for (int i = 5; i <= 21; i++){
cout << setw(2) << right << ' ' << ' '
<< setw(2) << right << i << '|';
for (int j = 1; j <= 10; j++){
cout << setw(5) << right << dec[basic.Score[i][j]];
}
cout << endl << " |" << endl;
}
// there are errors in the score table on scores 10 and 11
// I left them to show how easy it is to fix errors
// this is how it works
int card1 = 10, card2 = 3, dealercard = 10; //player has 13, dealer 10
decision d = basic.Score[card1 + card2][dealercard]; //player should...
cout << dec[d] << endl;
card1 = card2 = 8; //pair or 8's
dealercard = 10; // dealer has 10
d = basic.Pair[card1][dealercard]; //player should...
cout << dec[d] << endl;
return 0;
}
|