-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
660 lines (532 loc) · 25.1 KB
/
player.py
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
"""
Pokerbot 2013
Julian Chaidez, Katie Laverty, Varun Ramaswamy
"""
import argparse
import socket
import sys
from pbots_calc import calc
from random import random, randint
from numpy import polyfit, polyval, asscalar, float32
from json import loads, dumps
json_loads, json_dumps = loads, dumps
del loads, dumps
#GLOBAL MACROS#
#Basic deck, used to track contents of deck, might be useful for other things
DECK = set(['Ah','2h','3h','4h','5h','6h','7h','8h','9h','Th','Jh','Qh','Kh',
'Ad','2d','3d','4d','5d','6d','7d','8d','9d','Td','Jd','Qd','Kd',
'Ac','2c','3c','4c','5c','6c','7c','8c','9c','Tc','Jc','Qc','Kc',
'As','2s','3s','4s','5s','6s','7s','8s','9s','Ts','Js','Qs','Ks'])
#BODY CODE#
#OPPONENT CLASS#
class Opponent:
#This class models the behavior of an opponent using data like the opponent
#hand history and folding behavior.
#Assuming that the opponent players are determining betting values in the same
#way that we are, we can reconstruct a vague model for their betting strategy by
#using a polynomial approximation of their behavior.
#The libary structures intilialized in the constructor below will store families
#of polynomials parameterized as so. Let button be a variable indicating whether
#or not the opponent is the button, and let bet_round be the round of betting
#(0,1,2,3) taking place. Then
#self.history[button][bet_round]['bet' or 'equity'] = [list of bet or equity data points]
#self.e_to_b_lib[button][bet_round] = [polynomial array modeling equity to bet function]
#self.b_to_e_lib[button][bet_round] = [polynomial array modeling equity to bet function]
#self.equity_floor_lib[button][bet_round] = |estimated equity floor for these parameters|
#Constructor method
def __init__(self, name, bigBlind):
#LOCAL MACROS#
INITIAL_FOLDING_FREQUENCY = .3
INITIAL_FOLDING_SAMPLE_SIZE = 10
INIT_B_FLOOR, INIT_N_FLOOR = .4, .3 #These are the initial values for the
#MAIN CODE#
#Stores name
self.name = name
#Initializes history storage data structure
self.play_history = self.init_history()
#Initializes polynomial library data structure
self.e_to_b_lib = self.init_lib()
self.b_to_e_lib = self.init_lib()
self.equity_floor_lib = self.init_eq_lib(INIT_B_FLOOR, INIT_N_FLOOR)
#Calculates
self.redetermine_libs()
#Initializes current bet sequence variable
self.bet_sequence = [0,0,0,0]
#Initializes folding frequency variables
self.folding_frequency = INITIAL_FOLDING_FREQUENCY
self.folding_sample_size = INITIAL_FOLDING_SAMPLE_SIZE
#Stores half big blind value
self.bigBlind = bigBlind
#Utility function for turning sets and lists into strings. Used to make lists for
#input into 'calc' equity function. This might be better as a global function
def to_str(self,i): return str(i).split('[')[1].split(']')[0].replace(' ','').replace("'",'').replace(',','')
#Constructor for history dictionary
def init_history(self):
d = {}
d[True], d[False] = [], []
#We add these initial values to stabilize the initial polynomial as a near straight line.
for i in xrange(4):
d[True].append({'bet':[0,.001,.002,.998,.999,1],'equity':[0,.001,.002,.998,.999,1]})
d[False].append({'bet':[0,.001,.002,.998,.999,1],'equity':[0,.001,.002,.998,.999,1]})
return d
#Constructor for library dictionaries
def init_lib(self):
d = {}
d[True], d[False] = [[],[],[],[]], [[],[],[],[]]
return d
#Constructor for library dictionaries
def init_eq_lib(self,i,j):
d = {}
d[True], d[False] = [i,i,i,i], [j,j,j,j]
return d
#Exports data from this player in json format and returns it
def export_history(self):
d = dict()
d['name'] = self.name
d['play_history'] = self.play_history
d['e_to_b_lib'] = self.e_to_b_lib
d['b_to_e_lib'] = self.b_to_e_lib
d['equity_floor_lib'] = self.equity_floor_lib
d['folding_frequency'] = self.folding_frequency
d['foldin_sample_size'] = self.foldin_sample_size
return json_dump(d)
#Loads a saved data set about a player bot
def load_history(self, data):
d = json_loads(data)
self.name = d['name']
self.play_history = d['play_history']
self.e_to_b_lib = d['e_to_b_lib']
self.b_to_e_lib = d['b_to_e_lib']
self.equity_floor_lib = d['equity_floor_lib']
self.folding_frequency = d['folding_frequency']
self.folding_sample_size = d['foldin_sample_size']
#Adds single card point, and performs necessary recalculations to
#determine
def add_hand_data_pt(self, hand, board, bet_seq, button):
#LOCAL MACROS#
CALC_ITERS = 1000
POLY_DEGREE = 1
#MAIN CODE#
#Makes hand inut for equity calculation
h = hand + ':xx'
#For each betting phase with board cards
for i in xrange(0,4):
#Stores total bet made on that phase
self.play_history[button][i]['bet'].append(bet_seq[i])
#Stores equity of the hand that the opponent possesed at the time of the bet
if i == 0: b = ''
else: b = self.to_str(board[:3+i])
d = ''
e = calc(h,b,d,CALC_ITERS).ev[0]
self.play_history[button][i]['equity'].append(e)
#print '_____'
#print 'PLAY_HISTORY', i, button, self.play_history[button][i]
#print '_____'
#Performs polynomial regression to determine the equity to bet function and a bet to equity function
l1 = polyfit(self.play_history[button][i]['equity'], self.play_history[button][i]['bet'], POLY_DEGREE)
for k in range(POLY_DEGREE + 1): l1[k] = float(l1[k])
self.e_to_b_lib[button][i] = l1
l2 = polyfit(self.play_history[button][i]['bet'], self.play_history[button][i]['equity'], POLY_DEGREE)
for k in range(POLY_DEGREE + 1): l2[k] = float(l2[k])
self.b_to_e_lib[button][i] = l2
#Checks to see if equity threshold should change based on new betting evidence.
if e < self.equity_floor_lib[button][i]: self.equity_floor_lib[button][i] = e
#Recalculates the polynomial functions based on current play history
def redetermine_libs(self):
#LOCAL MACROS#
POLY_DEGREE = 1
#MAIN CODE#
for i in [True, False]:
for j in xrange(0,4):
#Performs polynomial regression to determine the equity to bet function and a bet to equity function
self.e_to_b_lib[i][j] = \
polyfit(self.play_history[i][j]['equity'], self.play_history[i][j]['bet'], POLY_DEGREE)
self.b_to_e_lib[i][j] = \
polyfit(self.play_history[i][j]['bet'], self.play_history[i][j]['equity'], POLY_DEGREE)
#Gets estimated opponent bet amount given equity, button and betting round.
def get_bet_amount(self, equity, round, button):
k, d = 0, len(self.b_to_e_lib[button][round])
for i in xrange(d):
k += float(self.e_to_b_lib[button][round][i]) * (equity ** (d - i - 1))
#print '**POLY_E_TO_B**', k
return k
#Gets estimated opponent equity given bet amount, button and betting round.
def get_equity(self, bet, round, button):
#print 'poly used:', self.b_to_e_lib[button][round]
k, d = 0, len(self.b_to_e_lib[button][round])
for i in xrange(d):
k += float(self.b_to_e_lib[button][round][i]) * (bet ** (d - i - 1))
#print '**POLY_B_TO_E**', k
return k
#Gets estimated opponent equity threshold given round and button
def get_equity_threshold(self, round, button):
return self.equity_floor_lib[button][round]
#BET SEQUENCE STORAGE AND PROCESSING#
#Resets the bet sequence for a new hand
def reset_bet_sequence(self):
self.bet_sequence = [0,0,0,0]
#Gets sequence of final bets by turn
def get_bet_sequence(self):
return self.bet_sequence
#Gets current opponent bet given round number
def get_current_bet(self, round):
return self.bet_sequence[round]
#Updates bet sequence given total pot contents, current bet and the betting round.
def update_bet_sequence(self, pot, player_bet, round):
self.bet_sequence[round] = (pot - player_bet) - (3 * (self.bigBlind / 2))
#END OF BET SEQUENCE STORAGE AND PROCESSING#
#FOLDING FREQUENCY STORAGE AND PROCESSING#
#Gets current folding frequency
def get_folding_frequency(self):
return self.folding_frequency
#Updates folding frequency
def update_folding_frequency(self, folded):
self.folding_frequency = ((self.folding_frequency * self.folding_sample_size) + folded)\
/(self.folding_sample_size + 1)
#END OF FOLDING FREQUENCY AND PROCESSING#
def get_polys(self, round, button):
return self.e_to_b_lib[button][round], self.b_to_e_lib[button][round]
#END OF OPPONENT CLASS
#PLAYER CLASS#
class Player:
#Constructor method
def __init__(self, test = False):
self.socket = None
self.saved_data = {}
self.test = test
#CLASS UTILITIES#
#Utility function for turning sets and lists into strings. Used to make lists for
#input into 'calc' equity function
def to_str(self,i): return str(i).split('[')[1].split(']')[0].replace(' ','').replace("'",'').replace(',','')
#Utility function that looks in list of actions and returns all actions of a given type
def find_actions(self, actions, type):
l = []
for action in actions:
if action[0] == type[0] and action[1] == type[1]: l.append(action)
return l
#Utility functions for normalizing and denormalizing value of total bet (to make it fraction of entire stack)
def normalize_bet(self, bet):
return float(bet) / float(self.stackSize * self.bigBlind)
def denormalize_bet(self, bet):
return round(bet * self.stackSize * self.bigBlind)
#END CLASS UTILITIES#
#Main runtime method
def run(self, input_socket):
# Get a file-object for reading packets from the socket.
# Using this ensures that you get exactly one packet per read.
self.socket = input_socket
f_in = self.socket.makefile()
print 'run socket success'
while True:
# Block until the engine sends us a packet.
input_str = f_in.readline()
message = self.process_input(input_str)
if message == 'BREAK':
break
elif message:
message += '\n'
self.socket.send(message)
# Clean up the socket.
self.socket.close()
#This function takes in message strings and returns the appropriate response
def process_input(self,input_str):
data = input_str.split()
message = None
# If data is None, connection has closed.
if not data: return 'BREAK'
else:
command = data[0]
# Otherwise, execute play based on recieved data
if command == "NEWGAME":
#Executes game initialization procedure
self.init_game(*data)
return None
elif command == "KEYVALUE":
#Processes key/value pair
return self.store_value(*data)
elif command == "REQUESTKEYVALUES":
#Returns key/value pairs for storage and finishes
return self.finish(*data)
elif command == "NEWHAND":
#Executes hand initialization procedure
self.init_hand(*data)
return None
elif command == "GETACTION":
#Executes main logic and performs relevant action
return self.play(data)
elif command == "HANDOVER":
#Executes end hand procedure
self.end_hand(data)
return None
else:
#Invalid command causes abort
return 'BREAK'
#Executes game initialization procedure
def init_game(self, command, name, oppName, stackSize, bb, numHands, timeBank):
self.name = name
self.opponent = Opponent(oppName, int(bb))
self.stackSize, self.bigBlind, self.numHands = int(stackSize), int(bb), int(numHands)
self.timeBank = float(timeBank)
#SAVING METHODS SECTION#
#This section contains the methods handling value storage and recovery. Nothing is really implemented here
#right now.
#Processes key/value pair
def store_value(self,command,key,val):
self.saved_data[key] = val
#Returns key/value pairs for storage and finishes
def finish(self, command, bytesLeft):
return 'FINISH'
#END OF SAVING METHODS SECTION#
#HAND INITIALIZATION METHOD SECTION#
#This section contains init_hand, the method handling NEWHAND calls, as well as
#all of the methods on which it is dependent.
#Executes hand initialization procedure
def init_hand(self, command, handId, button, holeCard1, holeCard2, holeCard3, yourBank, oppBank, timeBank):
self.handId, self.button = int(handId), bool(button)
self.bank, self.oppBank, self.timeBank = int(yourBank), int(oppBank), float(timeBank)
self.holeCards = set([holeCard1, holeCard2, holeCard3])
self.deck = DECK.copy()
for c in self.holeCards: self.deck.remove(c)
self.discards = set()
#Resets current bet count to 0
self.current_bet = 0
#Resets bet sequence of opponent model
self.opponent.reset_bet_sequence()
print '+++++++++++++++++++'
print '++begin hand:', self.handId, self.timeBank, '++'
#END OF HAND INITIALIZATION METHOD SECTION#
#PLAY METHOD SECTION#
#This section contains play, the method handling GETACTION calls, as well as
#all of the methods on which it is dependent.
#Executes main logic and performs relevant action
def play(self, data):
#FUNCTION MACROS#
REAL_PLAY_THRESHOLD = 30
#MAIN CODE#
#Parses data string into dictionary d
d = self.parse_getcommand(data)
#Identifies discard phase or betting phase
if 'DISCARD' in d['legalActions']: return self.discard(**d)
#else:
#if self.handId <= 30: return self.random_bet(**d)
else: return self.bet(**d)
#Parses getcommand data list into data dictionary
def parse_getcommand(self, data):
#Computes position of end of boardCards list
a = int(data[2]) + 3
#Computes position of end of lastActions list
b = a + int(data[a]) + 1
#Initializes the return dictionary and populates it
d = {}
d['potSize'] = int(data[1])
d['boardCards'] = data[3:a]
d['lastActions'] = data[a+1:b]
d['legalActions'] = data[b+1:-1]
d['timeBank'] = float(data[-1])
return d
#Computes correct card to discard
def discard(self, potSize, boardCards, lastActions, legalActions, timeBank):
#LOCAL MACROS#
CALC_ITERS = 1000
#MAIN CODE#
#Seeks to keep the cards that afford the maximum equity against an arbitrary pair of cards
#by computing the equity of 2 card subsets of hand
print 'time:', timeBank
v, l, discard = 0, list(self.holeCards), None
for i in xrange(3):
j = (i + 1) % 3
k = (i + 2) % 3
h = l[i] + l[j] + ':xx'
b = self.to_str(boardCards)
d = l[k]
c = calc(h,b,d,CALC_ITERS)
if c.ev[0] > v:
discard = l[k]
self.holeCards.remove(discard)
self.discards.add(discard)
return 'DISCARD:' + discard
#BET DETERMINATION METHOD SECTION#
#This section contains methods used to determine whether to fold and how much to bet#
#Random bet function determines betting randomly
#def random_bet(self, potSize, boardCards, lastActions, legalActions, timeBank):
#pass
#Computes correct bet (at the moment using only equity)
def bet(self, potSize, boardCards, lastActions, legalActions, timeBank):
#LOCAL MACROS#
CALC_ITERS = 1000
#MAIN CODE#
#Initial equity calculation
hole_cards_str = self.to_str(self.holeCards) + ':xxx'
board_cards_str = self.to_str(boardCards)
discard_str = self.to_str(self.discards)
e = calc(hole_cards_str, board_cards_str, discard_str, CALC_ITERS).ev[0]
#Gathers variables for input into threshold and bet functions
opponent = self.opponent
button = self.button
if len(boardCards) == 0: betting_round = 0
else: betting_round = len(boardCards) - 2
current_bet = self.normalize_bet(self.current_bet)
r1, r2 = random(), random()
print 'time:', timeBank
print 'betting round:', betting_round
print 'your_equity', e
#Updates current opponent bet
opponent.update_bet_sequence(potSize, self.current_bet, betting_round)
#Applies threshold function
if e < self.threshold_function(opponent, self.current_bet, button, betting_round, r1):
return self.try_fold(legalActions)
#If threshold is met, makes bet
else:
bet_amount = self.denormalize_bet(self.bet_function(opponent, e, button, betting_round, r2))
return self.try_bet(bet_amount, potSize, legalActions)
#Tries to bet a certain amount
def try_bet(self, new_amount, potSize, legalActions):
print '________'
print 'legalActions:', legalActions
print '________'
#Ensures that bet is not above stack size or below big blind
if self.current_bet - new_amount < self.bigBlind: new_amount = self.current_bet
elif new_amount > self.stackSize: new_amount = self.stackSize
#If new amount is too low, tries to perform checks and calls
if new_amount <= self.current_bet:
if 'CHECK' in legalActions: action = 'CHECK'
elif 'CALL' in legalActions: action = 'CALL'
#Otherwise, tries to implement bet to the level intended, if possible.
else:
if 'BET' in legalActions:
self.current_bet = new_amount
action = 'BET:' + str(new_amount - self.current_bet)
elif 'RAISE' in legalActions:
self.current_bet = new_amount
action = 'RAISE:' + str(potSize + new_amount - self.current_bet)
elif 'CALL' in legalActions: action = 'CALL'
elif 'CHECK' in legalActions: action = 'CHECK'
return action
#Tries to fold by taking the next best option if fold cannot be performed.
def try_fold(self, legalActions):
print '________'
print 'legalActions:', legalActions
print '________'
if 'FOLD' in legalActions: action = 'FOLD'
elif 'CHECK' in legalActions: action = 'CHECK'
elif 'CALL' in legalActions: action = 'CALL'
else: action = 'BET:' + str(self.bigBlind)
return action
#Outputs lowest acceptable equity given current situation
def threshold_function(self, opp, current_bet, self_button, round, r):
#LOCAL MACROS#
A = .2
B = .1
C = .3
D = .05
E = .05
F = .2
G = .01
#H = .1
#MAIN CODE#
#Gathering important data for actual metric function (variables numbered and lettered below)
opp_button = not self_button #1
opp_thresh = opp.get_equity_threshold(round, opp_button) #2
opp_bet = self.normalize_bet(opp.get_current_bet(round))
print '**opp_bet**', opp_bet
opp_equity = opp.get_equity(opp_bet, round, opp_button) #3
opp_fold_freq = opp.get_folding_frequency() #4
#Variables round and r (random variable in range 0-1) are metric variables 5 and 6 respectively
#Actual calculation takes place here
threshold = min(A, 1 - opp_fold_freq) + (B * r) + (C * (1 - opp_fold_freq)) + (D * opp_button)\
+ (E * ((opp_equity / (round + 1)) ** 2)) + (F * opp_thresh) + (G * current_bet)
'''
OLD THRESHOLD FUNCTION
threshold = float((A + (B * round)) * ((C * opp_thresh) + (D * (opp_equity ** 2)))\
+ (A - (B * round)) * ((F * opp_button) + (E * (opp_fold_freq ** 2)))\
+ (G * r) + H)
'''
#print opp.get_polys(round, self_button)
print 'opp_bet', opp.get_current_bet(round), self.normalize_bet(opp.get_current_bet(round))
print 'round:', round, 'button:', self_button, 'random:', r
print 'opp_threshold:', opp_thresh, 'opp_equity:', opp_equity, 'opp_fold_freq', opp_fold_freq
print 'fold threshold:', threshold
print '======'
return threshold
#Outputs amount that should be bet given current situation
def bet_function(self, opp, equity, self_button, round, r):
#LOCAL MACROS#
A = 0
B = .25
C = 1
D = .25
E = .1
F = .1
#MAIN CODE#
#Gathering important data for actual metric function (variables numbered and lettered below)
opp_button = not self_button #1
opp_real_bet = self.normalize_bet(opp.get_current_bet(round))
opp_equity = opp.get_equity(opp_real_bet, round, opp_button) #2
opp_rvrs_bet = opp.get_bet_amount(equity, round, self_button) #3
#Variables equity, round and r (random variable in range 0-1) are metric variables 4, 5 and 6 respectively
#Actual calculation takes place here
bet_amount = float((A + (B * (round + 1))) * ((C * (equity - opp_equity)) + (D * opp_rvrs_bet))\
+ (E * (self_button - .5) / (round + 1)) + (F * (r - .5)))
print opp.get_polys(round, self_button)
print 'opp_bet', opp.get_current_bet(round), opp_real_bet
print 'round:', round, 'button:', self_button, 'random:', r
print 'opp_equity:', opp_equity, 'opp_rvrs_bet:', opp_rvrs_bet
print 'bet_amount:', bet_amount
print '======'
return bet_amount
#END OF BET DETERMINATION METHOD SECTION#
#END OF PLAY METHOD SECTION#
#END HAND METHOD SECTION#
#This section contains end_hand, the method handling HANDOVER calls, as well as the functions on which
#it is dependent
#Executes end hand procedure
def end_hand(self, data):
#Parses input string
d = self.parse_handover(data)
#Finds all show actions given in final part of hand
l1 = self.find_actions(d['lastActions'],'SHOW')
if l1:
#If cards were shown, logs data in opponent model
for show in l1:
action, c1, c2, actor = show.split(':')
if actor == self.opponent.name:
h = c1 + c2
b = d['boardCards']
opp_bet_seq = []
for x in self.opponent.get_bet_sequence():
opp_bet_seq.append(self.normalize_bet(x))
#Normalizes bets to account for current
opp_button = not self.button
self.opponent.add_hand_data_pt(h, b, opp_bet_seq, opp_button)
l2 = self.find_actions(d['lastActions'],'FOLD')
opp_folded = (len(l2) and l2[0].split(':')[1] == self.opponent.name)
self.opponent.update_folding_frequency(opp_folded)
#print self.find_actions(d['lastActions'],'FOLD')
#print self.find_actions(d['lastActions'],'WIN')
print '++end hand++', self.timeBank
#Parses handover data list into data dictionary
def parse_handover(self, data):
#Computes position of end of boardCards list
a = int(data[3]) + 4
#Initializes the return dictionary and populates it
d = {}
d['yourBank'] = int(data[1])
d['oppBank'] = int(data[2])
d['boardCards'] = data[4:a]
d['lastActions'] = data[a+1:-1]
d['timeBank'] = float(data[-1])
return d
#END OF PLAY METHOD SECTION#
#END OF PLAYER CLASS$
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='A Pokerbot.', add_help=False, prog='pokerbot')
parser.add_argument('-h', dest='host', type=str, default='localhost', help='Host to connect to, defaults to localhost')
parser.add_argument('port', metavar='PORT', type=int, help='Port on host to connect to')
args = parser.parse_args()
# Create a socket connection to the engine.
try:
s = socket.create_connection((args.host, args.port))
except socket.error as e:
exit()
bot = Player()
bot.run(s)