-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokerBot.java
More file actions
344 lines (332 loc) · 12.2 KB
/
PokerBot.java
File metadata and controls
344 lines (332 loc) · 12.2 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import java.util.*;
public class PokerBot extends PokerPlayer {
private boolean opMode = false;
private PokerDeck p = new PokerDeck();
private int[][] hands = { { 14, 14 }, { 14, 13 }, { 14, 12 }, { 14, 11 }, { 14, 10 }, { 14, 9 }, { 14, 8 }, { 14, 2 },
{ 13, 13 }, { 13, 12 }, { 13, 11 }, { 13, 10 }, { 13, 9 }, { 13, 8 }, { 12, 12 }, { 12, 11 }, { 12, 10 },
{ 12, 9 }, { 12, 8 }, { 11, 11 }, { 11, 10 }, { 11, 9 }, { 11, 8 }, { 10, 10 }, { 9, 9 }, { 8, 8 }, { 7, 7 },
{ 6, 6 }, { 5, 5 }, { 4, 4 }, { 3, 3 }, { 2, 2 } }; // preset hands for smart bot
private boolean dumb; // dumb is basically if the bot should js do random stuff or have some decency
public PokerBot() {
super("temp");
randomName();
dumb = true;
if (Math.random() > 0.5)
dumb = false;
if (super.getName().equals("Aventurine")) {
opMode = true;
}
}
public void randomName() {
super.setName(Names.getName());
}
// funny
public void checkName() {
if (super.getName().equals("Aventurine")) {
opMode = true;
}
}
public int[] action(String round, int prevBet, int bet, int blind, Card[] board) {
if (dumb) { // idiot bot code, fixed percentages for all situations no matter what
int[] action = new int[2];
double rand = Math.random();
if (opMode && super.getChips() > 0) {
action[0] = 4;
action[1] = super.getChips();
} else if (bet < super.getChips()) {
if (rand >= 0 && rand < 0.75) { // 75% chance to call
action[0] = 1;
if (bet > 0) {
action[1] = (bet >= super.getChips()) ? super.getChips() : bet - prevBet;
} else
action[1] = (bet == 0) ? 0 : bet - prevBet;
} else if (rand >= 0.75 && rand < 0.85) { // 10% chance to raise
if (((bet == 0) ? blind : bet + blind) + super.getChips() / 10 < super.getChips()) {
// however, only raises if the bet meets certain conditions
int max;
int min;
if (round.equals("preflop")) {
max = super.getChips() / 10 + bet + blind;
min = bet + blind;
} else {
if (bet == 0) {
max = super.getChips() / 10 + blind;
min = blind;
} else {
max = super.getChips() / 10 + bet + blind;
min = bet + blind;
}
}
action[0] = 3;
action[1] = (int) (Math.random() * (max - min + 1) + min);
} else {
// if those "conditions" are not met, then has 15% to continue and all in the current bet, otherwise folds.
if (Math.random() > 0.85) {
action[0] = 4;
action[1] = super.getChips();
} else {
action[0] = 2;
}
}
} else if (rand >= 0.85 && rand < 0.97) { // 12% chance to call/fold
action[0] = (bet == 0) ? 1 : 2;
} else { // 3% chance to all in
action[0] = 4;
action[1] = super.getChips();
}
} else {
if (Math.random() > 0.8) {
action[0] = 4;
action[1] = super.getChips();
} else {
action[0] = 2;
}
}
return action;
} else { // intelligent bot code, varying percentages based on current siutation
int[] action = new int[2];
if (round.equals("preflop")) {
/*
* if hand is in the range, plays it only if bet is lower than half of current
* stack, otherwise, has a 80% chance to call and 20% chance of folding.
* for the former, 20% chance to raise, 80% chance to call.
* if hand is out of range, has a 25% chance to call and 75% chance of folding.
*/
boolean isHand = false;
for (int[] h : hands) {
if (Arrays.equals(Deck.cardToInt(super.getHand()), h)) {
isHand = true;
if (bet < super.getChips() / 2) {
if (Math.random() < 0.2) {
action[0] = 3;
action[1] = (bet == 0) ? (int) (blind * (Math.random() + 2)) : (int) (bet * (Math.random() + 2));
} else {
action[0] = 1;
if (bet > 0) {
action[1] = (bet >= super.getChips()) ? super.getChips() : bet - prevBet;
} else
action[1] = (bet == 0) ? 0 : bet - prevBet;
}
} else {
if (Math.random() < 0.8) {
action[0] = 1;
if (bet > 0) {
action[1] = (bet >= super.getChips()) ? super.getChips() : bet - prevBet;
} else
action[1] = (bet == 0) ? 0 : bet - prevBet;
} else {
action[0] = 2;
}
}
}
}
if (!isHand) {
if (bet < super.getChips() / 2 && Math.random() < 0.25) {
action[0] = 1;
action[1] = (bet == 0) ? 0 : bet - prevBet;
} else {
action[0] = 2;
}
}
} else {
// three betting settings: 0 - call 1 - bets/raise to 100-150% of current bet, 2
// - 150-300% of current bet, 3 - 300% to all in. 4 - fold
// if this has straight or flush: 0 - 25%, 1 - 55%, 2 - 15%, 3 - 5%, 4 - 0%.
// if full house: 0 - 5%, 1 - 35%, 2 - 45%, 3 - 15%, 4 - 0%.
// if four of kind or straight flush: 0 - 0%, 1 - 15%, 2 - 25%, 3 - 60%, 4 - 0%.
// drawing hand (2 pair, 3 o kind, straight/flush draw): 0 - 50%, 1 - 30%, 2 -
// 5%, 3 - 5%, 4 - 10% [given bet < half of curr stack], otherwise: 0 - 30%, 1 -
// 15%, 2 - 5%, 3 - 0%, 4 - 50%. replace fold chance with check chance
// all other hands: 0 - 65%, 1 - 10%, 2 - 5%, 3 - 0%, 4 - 20% [given bet < third
// of curr stack], otherwise: 0 - 25%, 1 - 5%, 2 - 0%, 3 - 0%, 4 - 70%, replace
// fold chance with check chance if applicable
// bot's behavior in a nutshell every time on its turn
int subAction = -1;
Card[] hand = new Card[5];
if (board.length == 3) {
hand[0] = super.getHand()[0];
hand[1] = super.getHand()[1];
for (int i = 0; i < 3; i++)
hand[i + 2] = board[i];
} else {
hand = p.getBestHand(super.getHand(), board);
}
int rank = p.getRanking(hand);
int rand = (int) (Math.random() * 101 + 1);
if (rank == 5 || rank == 4) {
if (rand <= 25) {
subAction = 0;
} else if (rand > 25 && rand <= 80) {
subAction = 1;
} else if (rand > 80 && rand <= 95) {
subAction = 2;
} else {
subAction = 3;
}
} else if (rank == 3) {
if (rand <= 5) {
subAction = 0;
} else if (rand > 5 && rand <= 40) {
subAction = 1;
} else if (rand > 40 && rand <= 85) {
subAction = 2;
} else {
subAction = 3;
}
} else if (rank < 3) {
if (rand <= 15) {
subAction = 1;
} else if (rand > 15 && rand <= 40) {
subAction = 2;
} else {
subAction = 3;
}
} else {
Card[] temp = new Card[2 + board.length];
temp[0] = super.getHand()[0];
temp[1] = super.getHand()[1];
for (int i = 0; i < board.length; i++)
temp[i + 2] = board[i];
boolean[] draw = draw(temp);
if (rank == 6 || rank == 7 || ((draw[0] || draw[1]) && board.length < 5)) {
if (bet < super.getChips() / 2) {
if (rand <= 50) {
subAction = 0;
} else if (rand > 50 && rand <= 80) {
subAction = 1;
} else if (rand > 80 && rand <= 85) {
subAction = 2;
} else if (rand > 85 && rand <= 90) {
subAction = 3;
} else {
subAction = 4;
}
} else {
if (rand <= 30) {
subAction = 0;
} else if (rand > 30 && rand <= 45) {
subAction = 1;
} else if (rand > 45 && rand <= 50) {
subAction = 2;
} else {
subAction = 4;
}
}
} else {
if (bet < super.getChips() / 3) {
if (rand <= 65) {
subAction = 0;
} else if (rand > 65 && rand <= 75) {
subAction = 1;
} else if (rand > 75 && rand <= 80) {
subAction = 2;
} else {
subAction = 4;
}
} else {
if (rand <= 25) {
subAction = 0;
} else if (rand > 25 && rand <= 30) {
subAction = 1;
} else {
subAction = 4;
}
}
}
}
boolean zeroBet = false;
if (bet == 0) {
bet = blind;
zeroBet = true;
}
switch (subAction) {
case 0:
action[0] = 1;
if (!zeroBet) {
action[1] = (bet >= super.getChips()) ? super.getChips() : bet - prevBet;
} else
action[1] = (zeroBet) ? 0 : bet - prevBet;
break;
case 1:
action[0] = 3;
action[1] = (int) ((Math.random() * .6 + 2) * bet);
break;
case 2:
action[0] = 3;
action[1] = (int) ((Math.random() * 1.6 + 2.5) * bet);
break;
case 3:
double upper = (double) super.getChips() / bet;
action[0] = 3;
action[1] = (int) ((Math.random() * (upper - 2 + 0.1) + 4) * bet);
break;
case 4:
if (!zeroBet)
action[0] = 2;
else
action[0] = 1;
break;
}
}
if (action[1] >= super.getChips()) {
action[0] = 4;
action[1] = super.getChips();
}
return action;
}
}
public boolean[] draw(Card[] total) {
// checks to see if the combined hand and board contains a draw, i.e. 4 cards in
// a straight or 4 cards in a flush (draw for full house is js two pair or three
// of a kind)
Deck.sort(total);
int straightCount = 0;
for (int i = 1; i < total.length; i++) {
if (straightCount < 4) {
if (total[i].getNum() == total[i - 1].getNum() + 1)
straightCount++;
else
straightCount = 0;
} else {
break;
}
}
int[] flushCount = new int[4]; // indexing: 0 - spades, 1 - clubs, 2 - diamonds, 3 - hearts
boolean flushDraw = false;
for (Card d : total) {
String suit = d.getValue().substring(1);
switch (suit) {
case "♠️":
flushCount[0]++;
break;
case "♣️":
flushCount[1]++;
break;
case "♦️":
flushCount[2]++;
break;
case "♥️":
flushCount[3]++;
break;
}
}
for (int i : flushCount)
if (i >= 4)
flushDraw = true;
return new boolean[] { straightCount > 3, flushDraw };
}
}
class Names { // avoid dupe names
private static ArrayList<String> names = new ArrayList<String>(
Arrays.asList(new String[] { "Bob", "Rob", "Alice", "Aaron", "Sam", "Eddie", "Rachel", "Mike", "Charlie", "Ellie",
"Colin", "Kevin", "Victor", "Robin", "Jean", "Katheryne", "Dan", "Mark", "Richard", "Dana", "Elena", "Joe",
"Juan", "Tony", "Ella", "Sammy", "Edward", "Ethan", "Jonathan", "Jason", "Evelyn", "Josie", "Sophia", "Bryan",
"Allen", "Alan", "Kim", "Chloe", "Claire", "Jerry", "Toby", "Scarlet", "Alex", "Leon", "Eric",
"GuyWhoGoesAllInEveryTime", "Fei Yu-Ching", "Jay", "Daniel", "Evan", "Sean", "Selene", "James", "Jacques",
"NoName", "Zoe", "Sarah", "Kyle", "Irene", "Sharolyn", "Ben", "Coco", "Cindy", "Megan", "Mia", "E10WINS",
"Audrey", "Emily", "March 7th", "Stelle", "Cao Cao", "Liu", "Camellia", "Cameron", "Maddie", "Will", "Amy",
"Kelly", "Aventurine" }));
public static String getName() {
return names.remove((int) (Math.random() * names.size()));
}
}