-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerAI.h
203 lines (184 loc) · 3.65 KB
/
playerAI.h
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
#ifndef PLAYERAI_H
#define PLAYERAI_H
/*
0 = stand
1 = hit
2 = double or hit
3 = double or stand
4 = surrender
5 = split
6 = split or hit
*/
//player 9-16 against dealer card
const int DealerS17Multideck_Hard[8][10] =
{
{1, 2, 2, 2, 2, 1, 1, 1, 1, 1},
{2, 2, 2, 2, 2, 2, 2, 2, 1, 1},
{2, 2, 2, 2, 2, 2, 2, 2, 2, 1},
{1, 1, 0, 0, 0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1, 4, 1},
{0, 0, 0, 0, 0, 1, 1, 4, 4, 4}
};
//player soft 13-18 against dealer
const int DealerS17Multideck_Soft[6][10] =
{
{1, 1, 1, 2, 2, 1, 1, 1, 1, 1},
{1, 1, 1, 2, 2, 1, 1, 1, 1, 1},
{1, 1, 2, 2, 2, 1, 1, 1, 1, 1},
{1, 1, 2, 2, 2, 1, 1, 1, 1, 1},
{1, 2, 2, 2, 2, 1, 1, 1, 1, 1},
{0, 3, 3, 3, 3, 0, 0, 1, 1, 1}
};
const int DealerS17Multideck_Split[9][10] =
{
{6, 6, 5, 5, 5, 5, 1, 1, 1, 1},
{6, 6, 5, 5, 5, 5, 1, 1, 1, 1},
{1, 1, 1, 6, 6, 1, 1, 1, 1, 1},
{2, 2, 2, 2, 2, 2, 2, 2, 1, 1}, //treat pair of 5s as a hard 10
{6, 5, 5, 5, 5, 1, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 5, 5, 5, 5},
{5, 5, 5, 5, 5, 0, 5, 5, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //always stand on pair of 10s
};
#include <iostream>
#include <string>
//#include "hilowcount.h"
#include "blackjack.h"
using namespace std;
//extern enum states; //dont need this?
class PlayerAI
{
public:
string &playHand(const Hand *hand, int dealerUpcard, int numHands, int count, states state)
{
switch(state)
{
case BUYIN:
output = "10000";
return output;
case BET:
if(count <= 0)
output = "10";
else if(count == 1)
output = "25";
else if(count == 2)
output = "50";
else if(count == 3)
output = "75";
else if(count >= 4)
output = "100";
/* conservative betting */
/*if(count <= 1)
output = "10";
else if(count == 2)
output = "20";
else if(count == 3)
output = "30";
else if(count >= 4)
output = "40";*/
/*else if(count >= 5)
output = "50";
else if(count >= 6)
output = "60";*/
//output = "10"; //flat betting
return output;
case PLAY:
if(hand->isSplittable(numHands))
{
if(hand->getTotal() == 12 && hand->isSoft()) //split your aces. this needs a special case due to the way hand totals are calculated
{
output = "p";
}
else
{
tempindex = DealerS17Multideck_Split[(hand->getTotal()>>1) - 2][dealerUpcard-2];
action(hand, tempindex);
}
}
else if(hand->isSoft())
{
//if(hand->getTotal() == 12)
// exit(12); //should never reach here
if(hand->getTotal() >= 19)
{
output = "s";
}
else
{
tempindex = DealerS17Multideck_Soft[hand->getTotal()-13][dealerUpcard-2];
action(hand, tempindex);
}
}
else
{
if(hand->getTotal() <= 8)
{
output = "h";
}
else if(hand->getTotal() >= 17)
{
output = "s";
}
else
{
tempindex = DealerS17Multideck_Hard[hand->getTotal()-9][dealerUpcard-2];
action(hand, tempindex);
}
}
return output;
case INSURANCE:
output = "n";
return output;
default:
//should never reach here
exit(1007);
};
}
private:
string output;
int tempindex;
void action(const Hand *hand, int in)
{
if(in == 0)
{
output = "s";
}
else if(in == 1)
{
output = "h";
}
else if(in == 2)
{
if(hand->numCards() == 2)
output = "d";
else
output = "h";
}
else if(in == 3)
{
if(hand->numCards() == 2)
output = "d";
else
output = "s";
}
else if(in == 4)
{
if(hand->numCards() == 2)
output = "r";
else
output = "h";
}
else if(in == 5)
{
output = "p";
}
else if(in == 6)
{
output = "p";
}
}
};
#endif