def preflop_strategy(self): """ Returns an action before the flop, based on the table and the player """ # This calls Zach's preflop evaluator preflop_percentile = self.evaluate_preflop() potodds_ratio = 0.50 pot_size = 800 - self.opponent['stack'] - self.stack for action in self.legal: if isinstance(action, Bet): if preflop_percentile < 1: value_bet = int( round(potodds_ratio * preflop_percentile * pot_size / (1 - preflop_percentile))) if value_bet >= self.stack: return Bet(self.stack) elif value_bet > 0: return Bet(value_bet) else: return Check() else: return Bet(self.stack) # go all-in elif isinstance(action, Raise): chips_to_add = pot_size - 2 * self.pip if preflop_percentile < 1: value_bet = int( round(potodds_ratio * preflop_percentile * pot_size / (1 - preflop_percentile))) if value_bet >= self.stack: return Raise(self.stack + self.pip) elif value_bet >= 2 * chips_to_add: return Raise(value_bet + self.pip) elif value_bet >= chips_to_add: return Call() else: return Fold() else: return Raise(self.stack + self.pip) # go all-in # if something screws up, try checking return Check()
def river_strategy(self): """ Returns an action after the river, based on the table and the player """ # This calls Zach's river evaluator river_percentile = self.percentiles['river'] potodds_ratio = 0.50 pot_size = self.pot for action in self.legal: if isinstance(action, Bet): if river_percentile < 1: value_bet = int( round(potodds_ratio * river_percentile * pot_size / (1 - river_percentile))) if value_bet >= self.stack: return Bet(self.stack) elif value_bet > 0: return Bet(value_bet) else: return Check() else: return Bet(self.stack) # go all-in elif isinstance(action, Raise): chips_to_add = pot_size - 2 * self.pip if river_percentile < 1: value_bet = int( round(potodds_ratio * river_percentile * pot_size / (1 - river_percentile))) if value_bet >= self.stack: return Raise(self.stack + self.pip) elif value_bet >= 2 * chips_to_add: return Raise(value_bet + self.pip) elif value_bet >= chips_to_add: return Call() else: return Fold() else: return Raise(self.stack + self.pip) # go all-in # if something screws up, try checking return Check()
def respond(self): """Based on your game state variables (see the __init__), make a decision and return an action. If you return an illegal action, the engine will automatically check/fold you """ for action in self.legal: if isinstance(action, Raise): if self.hand[0].rank == self.hand[1].rank: return Raise(self.stack + self.pip) return Call() if isinstance(action, Bet): if randint(0, 100) < 35: return Bet(self.stack / 2) else: return Check() return Call()
def strategy(self, street, percentile): """ Returns an action before the flop, based on the table and the player """ x = percentile A = self.potodds_ratio_fixed * ( 1 - self.p3) + self.potodds_ratio_variable * self.p3 s = self.slow_play_threshold if x <= s: alpha = A * x / s elif x <= 1.0: alpha = A * (1 - x) / (1 - s) else: if s < 1: alpha = 0 else: alpha = A if alpha < 1: value_bet = int(round(alpha / (1 - alpha) * self.pot)) else: value_bet = self.stack alphacall = A * x if alphacall < 1: value_call = int(round(alphacall / (1 - alphacall) * self.pot)) else: value_call = self.stack if street == 5: value_bet = value_call """ print('self.hand ',self.hand) print('x ',x) print('alpha ',alpha) print('value_call ',value_call) """ self.opponent_potodds_estimate = 2 * ( self.opponent['pip'] - self.opponent_previous_pip) / self.pot self.opponent_previous_pip = self.opponent['pip'] for action in self.legal: if isinstance(action, Bet): if x < 1: if value_bet >= self.stack: if self.debug: print('Going All In, betting ', self.stack) ok = raw_input('press enter\n') return Bet(self.stack) elif value_bet > 0: if self.debug: print('Betting ', value_bet) ok = raw_input('press enter\n') return Bet(value_bet) else: if self.debug: print('Checking because value_bet=', value_bet) ok = raw_input('press enter\n') return Check() else: if self.debug: print('Going All In, betting ', self.stack) ok = raw_input('press enter\n') return Bet(self.stack) # go all-in elif isinstance(action, Raise): chips_to_add = self.opponent[ 'pip'] - self.pip #size of opponent's bet #for us, this is uniform on [0, 2*self.potodds_ratio] self.potodds_ratio_variable = ( (1 - self.p4) * self.potodds_ratio_variable + self.p4 * self.opponent_potodds_estimate) if x < 1: if value_bet >= self.stack: if value_bet <= chips_to_add: if self.debug: print('Calling to go all-in') ok = raw_input('press enter\n') return Call() else: if self.debug: print('Raising to go all-in. Raising to ', self.stack + self.pip) ok = raw_input('press enter\n') return Raise(self.stack + self.pip) elif value_bet >= 2 * chips_to_add: if self.debug: print('Raising to ', value_bet + self.pip) ok = raw_input('press enter\n') return Raise(value_bet + self.pip) elif value_call >= chips_to_add: if self.debug: print('Calling') ok = raw_input('press enter\n') return Call() else: if self.debug: print('Folding') ok = raw_input('press enter\n') return Fold() else: if self.debug: print('Going all-in, raising to ', self.stack + self.pip) ok = raw_input('press enter\n') return Raise(self.stack + self.pip) # go all-in elif isinstance(action, Call): #only options are calling and folding chips_to_add = self.opponent[ 'pip'] - self.pip #size of opponent's bet #for us, this is uniform on [0, 2*self.potodds_ratio] self.potodds_ratio_variable = ( (1 - self.p4) * self.potodds_ratio_variable + self.p4 * self.opponent_potodds_estimate) if x < 1: if value_call >= chips_to_add: if self.debug: print('Calling') ok = raw_input('press enter\n') return Call() else: if self.debug: print('Folding') ok = raw_input('press enter\n') return Fold() else: if self.debug: print('Going all-in, raising to ', self.stack + self.pip) ok = raw_input('press enter\n') return Raise(self.stack + self.pip) # go all-in # if something screws up, try checking if self.debug: print('Something screwed up, so we are checking (2)') ok = raw_input('press enter\n') return Check()
def strategy(self, street, percentile): """ Returns an action before the flop, based on the table and the player """ x = percentile if self.potodds_ratio_showdown > 0: A = (self.potodds_ratio_fixed * (1 - self.p3) + self.potodds_ratio_showdown * self.p3 * self.p5 + self.potodds_ratio_variable * self.p3 * (1 - self.p5)) else: A = self.potodds_ratio_fixed * ( 1 - self.p3) + self.potodds_ratio_variable * self.p3 #print 'showdown',self.potodds_ratio_showdown #print 'bet',self.potodds_ratio_variable s = self.slow_play_threshold if x <= s: #alpha = A*x/s alpha = A * x elif x <= 1.0: #alpha = A*(1-x)/(1-s) alpha = 0 if alpha < 1: value_bet = int(round(alpha / (1 - alpha) * self.pot)) else: value_bet = self.stack alphacall = A * x if alphacall < 1: value_call = int(round(alphacall / (1 - alphacall) * self.pot)) else: value_call = self.stack if street == 5 or street == 1: value_bet = value_call if self.opponent_showdown_potodds_estimate > 0 and self.corr > 0.9: self.potodds_ratio_showdown = self.opponent_showdown_potodds_estimate #else: # self.potodds_ratio_showdown = 0.0 #[vivek] do we really want this to be set to 0 here? self.opponent_potodds_estimate = 2 * ( self.opponent['pip'] - self.opponent_previous_pip) / self.pot self.opponent_previous_pip = self.opponent['pip'] for action in self.legal: if isinstance(action, Bet): if x < 1: if value_bet >= self.stack: if self.debug: print('Going All In, betting ', self.stack) ok = raw_input('press enter\n') return Bet(self.stack) elif value_bet > 0: if self.debug: print('Betting ', value_bet) ok = raw_input('press enter\n') return Bet(value_bet) else: if self.debug: print('Checking because value_bet=', value_bet) ok = raw_input('press enter\n') return Check() else: if self.debug: print('Going All In, betting ', self.stack) ok = raw_input('press enter\n') return Bet(self.stack) # go all-in elif isinstance(action, Raise): chips_to_add = self.opponent[ 'pip'] - self.pip #size of opponent's bet #for us, this is uniform on [0, 2*self.potodds_ratio] self.potodds_ratio_variable = ( (1 - self.p4) * self.potodds_ratio_variable + self.p4 * self.opponent_potodds_estimate) if x > s: #reraise gently to bleed bleed bleed if 2 * chips_to_add <= self.stack: return Raise(self.pip + 2 * chips_to_add) else: return Raise(self.stack + self.pip) elif x < 1: if value_bet >= self.stack: if value_bet <= chips_to_add: if self.debug: print('Calling to go all-in') ok = raw_input('press enter\n') return Call() else: if self.debug: print('Raising to go all-in. Raising to ', self.stack + self.pip) ok = raw_input('press enter\n') return Raise(self.stack + self.pip) elif value_bet >= 2 * chips_to_add: if self.debug: print('Raising to ', value_bet + self.pip) ok = raw_input('press enter\n') return Raise(value_bet + self.pip) elif value_call >= chips_to_add: if self.debug: print('Calling') ok = raw_input('press enter\n') return Call() else: if self.debug: print('Folding') ok = raw_input('press enter\n') return Fold() else: if self.debug: print('Going all-in, raising to ', self.stack + self.pip) ok = raw_input('press enter\n') return Raise(self.stack + self.pip) # go all-in elif isinstance(action, Call): #only options are calling and folding chips_to_add = self.opponent[ 'pip'] - self.pip #size of opponent's bet #for us, this is uniform on [0, 2*self.potodds_ratio] self.potodds_ratio_variable = ( (1 - self.p4) * self.potodds_ratio_variable + self.p4 * self.opponent_potodds_estimate) if x < 1: if value_call >= chips_to_add: if self.debug: print('Calling') ok = raw_input('press enter\n') return Call() else: if self.debug: print('Folding') ok = raw_input('press enter\n') return Fold() else: if self.debug: print('Going all-in, raising to ', self.stack + self.pip) ok = raw_input('press enter\n') return Raise(self.stack + self.pip) # go all-in # if something screws up, try checking if self.debug: print('Something screwed up, so we are checking (2)') ok = raw_input('press enter\n') return Check()
def strategy(self, street, percentile): """ Returns an action before the flop, based on the table and the player """ if len(self.opponent_bet_history) > self.p5: self.opponent_bet_history = self.opponent_bet_history[-self.p5:] mu = mean(self.opponent_bet_history) sigma = std(self.opponent_bet_history) x = percentile s = self.slow_play_threshold A = self.p1 * (1 - self.p7) + self.potodds_ratio_variable * self.p7 #print self.opponent['pip'],self.opponent_previous_pip opponent_bet = 1.0 * (self.opponent['pip'] - self.opponent_previous_pip) / self.pot self.opponent_previous_pip = self.opponent['pip'] chips_to_add = self.opponent['pip'] - self.pip #size of opponent's bet # predict opponents strength based on their bets if opponent_bet > 0: self.opponent_bet_history.append(opponent_bet) self.potodds_ratio_variable = ( (1 - 1.0 / self.p6) * self.potodds_ratio_variable + 2.0 / self.p6 * opponent_bet) y = 1.0 * sum(opponent_bet > array(self.opponent_bet_history) ) / len(self.opponent_bet_history) + 0.5 * sum( opponent_bet == array(self.opponent_bet_history) ) / len(self.opponent_bet_history) if x == 1 and y == 1: z == 1 else: z = x * (1 - y) / (x * (1 - y) + (1 - x) * y) * self.p8 + x * (1 - self.p8) if len(self.opponent_bet_history ) >= self.p5 / 2 and sigma / mu > 0.1: x = z if x <= s: alpha = A * x elif x <= 1.0: alpha = 0 if alpha < 1: value_bet = int(round(alpha / (1 - alpha) * self.pot)) else: value_bet = self.stack if x <= s: alphacall = A * x elif x <= 1: alphacall = 1 #make sure we call anything in our slowplay zone if alphacall < 1: value_call = int(round(alphacall / (1 - alphacall) * self.pot)) else: value_call = self.stack #print alphacall,value_call if street == 5: value_bet = value_call for action in self.legal: if isinstance(action, Bet): if value_bet >= self.stack: return Bet(self.stack) elif value_bet > 0: return Bet(value_bet) elif isinstance(action, Raise): if x > s: # pump money out with reraising (always min raise) random_addition = int(floor(3 * random.rand(1))) #random between 0 and 2 to throw off pattern-recognizers for string bets if 2 * chips_to_add + random_addition <= self.stack: return Raise(self.pip + 2 * chips_to_add + random_addition) else: return Raise(self.stack + self.pip) else: if value_bet >= self.stack: if value_bet <= chips_to_add: return Call() else: return Raise(self.stack + self.pip) elif value_bet >= 2 * chips_to_add: if False: #self.played_this_street > 1: #defense against bleeding return Call() else: return Raise(value_bet + self.pip) elif value_call >= chips_to_add: return Call() else: return Fold() elif isinstance(action, Call): #only options are calling and folding if value_call >= chips_to_add: return Call() else: return Fold() # if something screws up, try checking return Check()
def respond(self): """Based on your game state variables (see the __init__), make a decision and return an action. If you return an illegal action, the engine will automatically check/fold you """ preflop_matrix = [ [87, 169, 168, 166, 167, 165, 159, 149, 135, 121, 105, 86, 59], [163, 66, 164, 161, 162, 160, 157, 144, 131, 116, 98, 80, 53], [158, 150, 48, 153, 154, 151, 148, 140, 125, 111, 93, 74, 49], [155, 146, 136, 27, 145, 141, 137, 130, 122, 107, 89, 69, 41], [156, 147, 138, 128, 17, 133, 127, 120, 112, 102, 81, 62, 42], [152, 143, 134, 124, 115, 9, 117, 109, 101, 92, 77, 58, 36], [142, 139, 129, 119, 110, 100, 7, 99, 91, 79, 68, 51, 32], [132, 126, 123, 113, 103, 94, 83, 6, 78, 70, 56, 40, 25], [118, 114, 108, 106, 96, 84, 73, 64, 5, 57, 47, 33, 19], [104, 97, 95, 90, 85, 75, 65, 55, 45, 4, 39, 26, 15], [88, 82, 76, 72, 67, 61, 52, 43, 34, 28, 3, 23, 14], [71, 63, 60, 54, 50, 44, 37, 29, 22, 20, 16, 2, 12], [46, 38, 35, 30, 31, 24, 21, 18, 13, 11, 10, 8, 1] ] preflop_count = [ 3, 3, 3, 3, 3, 3, 3, 2, 3, 2, 2, 6, 2, 6, 6, 2, 3, 2, 6, 2, 2, 2, 6, 2, 6, 6, 3, 2, 2, 2, 2, 6, 6, 2, 2, 6, 2, 2, 6, 6, 6, 6, 2, 2, 2, 2, 6, 3, 6, 2, 6, 2, 6, 2, 2, 6, 6, 6, 6, 2, 2, 6, 2, 2, 2, 3, 2, 6, 6, 6, 2, 2, 2, 6, 2, 2, 6, 6, 6, 6, 6, 2, 2, 2, 2, 6, 3, 2, 6, 2, 6, 6, 6, 2, 2, 2, 2, 6, 6, 2, 6, 6, 2, 2, 6, 2, 6, 2, 6, 2, 6, 6, 2, 2, 2, 6, 6, 2, 2, 6, 6, 6, 2, 2, 6, 2, 6, 2, 2, 6, 6, 2, 6, 2, 6, 2, 6, 2, 2, 6, 6, 2, 2, 6, 6, 2, 2, 6, 6, 2, 6, 2, 6, 6, 2, 2, 6, 2, 6, 6, 6, 6, 2, 6, 6, 6, 6, 6, 6 ] count_sum = 663.0 sorted_rank = sorted([self.hand[0].rank, self.hand[1].rank]) if self.hand[0].suit == self.hand[1].suit: preflop_num = preflop_matrix[sorted_rank[1] - 2][sorted_rank[0] - 2] else: preflop_num = preflop_matrix[sorted_rank[0] - 2][sorted_rank[1] - 2] if preflop_num == 1: preflop_value = 1 else: preflop_value = 1 - sum( preflop_count[0:preflop_num - 1]) / count_sum if not self.board: for action in self.legal: if isinstance(action, Raise): if preflop_value > 0.95: return Raise(100) ## elif preflop_value > 0.75: ## return Raise(self.pip) ## elif preflop_value > 0.25: ## return Call() return Fold() elif isinstance(action, Bet): if preflop_value > 0.95: return Bet(100) ## elif preflop_value > 0.75: ## return Bet(self.pip) return Check() #print self.pip #print self.board[0] #+ self.opponent.stack + self.pip + self.stack for action in self.legal: if isinstance(action, Raise): if preflop_value > 0.95: return Call() else: return Fold() return Check()
def respond(self, brain): """Based on your game state variables (see the __init__), make a decision and return an action. If you return an illegal action, the engine will automatically fold you """ self.action = [] for act in brain.actions[-3:]: act_type = brain.classify(act[1]) self.action.append((act_type,0 if act_type not in [RAISE,BET] else act[1].amount)) if not brain.board.flop(): street = PREFLOP elif not brain.board.turn(): street = FLOP elif not brain.board.river(): street = TURN else: street = RIVER self.che = 0 ##SB calls self.fir = 0 ##on SB self.chebet = [[0,0],[0,0],[0,0]] ##BB raise after call self.dealbet = [[0,0],[0,0],[0,0]] ##SB raise self.chebetrai = [[0,0],[0,0],[0,0]] ##Our opponent Check raises us self.betrai = [[0,0],[0,0],[0,0]] ##We bet then our opponent raises self.betrairai = [[0,0],[0,0],[0,0]] ##We raise from sb then bb re-raises self.eq = self.parameterize(brain.ev,street) self.min = max(brain.opponent['pip']*2,brain.bb) self.oppmin = max(brain.pip*2,brain.bb) if self.action[-1][0] in [POST,DEAL] or self.action[-2][0] in [POST,DEAL]: self.myallin = brain.stack+brain.pip self.oppallin = brain.opponent['stack'] + brain.opponent['pip'] if brain.ev<0.5: self.valuebet = max(brain.pot/2, brain.bb*3) else: self.valuebet = max(brain.pot,brain.bb*4,(brain.pot-brain.pot*brain.ev)/(brain.ev)) if not brain.board.flop(): self.preflop(brain) elif not brain.board.turn(): self.flop(brain) elif not brain.board.river(): self.turn(brain) else: self.river(brain) if brain.hands_played_against > 20 and self.learning: self.statoverride(brain) my_action = self.nextaction(brain,street) if DEBUG: print "taking action",my_action, "from the ",street # Check that our action is legal for action in brain.legal: if isinstance(action,type(my_action)): break else: if isinstance(my_action, Raise): #see if we can bet if we can't raise for action in brain.legal: if isinstance(action,Bet): my_action = Bet(my_action.amount) break else: for action in brain.legal: if isinstance(action,Call): #otherwise see if we can bet my_action = Call() break else: my_action = None else: my_action = None # check fold if we selected no action if my_action == None: for action in brain.legal: if isinstance(action, Check): my_action = action break else: my_action = Fold() action = brain.classify(my_action) if action in [RAISE,BET]: if my_action.amount < self.min: my_action.amount = self.min if my_action.amount > brain.stack + brain.pip: my_action.amount = brain.stack + brain.pip # for action in brain.legal: # if isinstance(action, Call): # my_action = action # break # else: # my_action = Check() if DEBUG: print "taking action",my_action return my_action
def strategy(self, street, percentile): """ Returns an action before the flop, based on the table and the player """ """ if street == 2: if self.button: if self.played_this_street > 2: self.slowplay_flag = True #they're f*****g with us else: if self.played_this_street > 1: self.slowplay_flag = True #they're f*****g with us else: if self.button: if self.played_this_street > 1: self.slowplay_flag = True #they're f*****g with us else: if self.played_this_street > 2: self.slowplay_flag = True #they're f*****g with us if street == 2 and random.rand(1) < self.p9: #stab at pot p9% of the time if (self.pot == self.bb+self.sb): return Raise(self.pot*4) elif self.pot == self.bb*2: return Bet(self.pot*4) """ if self.played_this_street > 1: self.slowplay_flag = True if len(self.opponent_bet_history) > self.p5: self.opponent_bet_history = self.opponent_bet_history[-self.p5:] mu = mean(self.opponent_bet_history) sigma = std(self.opponent_bet_history) x = percentile s = self.slow_play_threshold A = self.p1 * (1 - self.p7) + self.potodds_ratio_variable * self.p7 #print self.opponent['pip'],self.opponent_previous_pip opponent_bet = 1.0 * (self.opponent['pip'] - self.opponent_previous_pip) / self.pot self.opponent_previous_pip = self.opponent['pip'] chips_to_add = self.opponent['pip'] - self.pip #size of opponent's bet # predict opponents strength based on their bets if opponent_bet > 0: self.opponent_bet_history.append(opponent_bet) self.potodds_ratio_variable = ( (1 - 1.0 / self.p6) * self.potodds_ratio_variable + 2.0 / self.p6 * opponent_bet) y = 1.0 * sum(opponent_bet > array(self.opponent_bet_history) ) / len(self.opponent_bet_history) + 0.5 * sum( opponent_bet == array(self.opponent_bet_history) ) / len(self.opponent_bet_history) if x == 1 and y == 1: z == 1 else: z = x * (1 - y) / (x * (1 - y) + (1 - x) * y) * self.p8 + x * (1 - self.p8) if len(self.opponent_bet_history ) >= self.p5 / 2 and sigma / mu > 0.1 and street > 2: x = z if x <= s: alpha = A * x elif x <= 1.0: alpha = 0 if alpha < 1: value_bet = int(round(alpha / (1 - alpha) * self.pot)) else: value_bet = self.stack if x <= s: alphacall = A * x elif x <= 1: alphacall = 1 #make sure we call anything in our slowplay zone if alphacall < 1: value_call = int(round(alphacall / (1 - alphacall) * self.pot)) else: value_call = self.stack #print alphacall,value_call if street == 5: value_bet = value_call for action in self.legal: if isinstance(action, Bet): if not (self.button) and (street == 3 or street == 4 ): # first to act after flop,turn self.played_this_street -= 1 #won't count this check as playing return Check() if x > s and self.button: # Second to act (in position) with nuts if self.slowplay_flag: #if they have good cards, lets push them return Bet(self.pot) else: value_bet = int(floor( .75 * self.pot * random.rand(1))) + int( round(.25 * self.pot)) if self.slowplay_flag: return Check() if value_bet >= self.stack: return Bet(self.stack) elif value_bet > 0: return Bet(value_bet) else: return Check() elif isinstance(action, Raise): if x > s: # pump money out with reraising (always min raise) random_addition = int(floor(3 * random.rand(1))) #random between 0 and 2 to throw off pattern-recognizers for string bets if 2 * chips_to_add + random_addition <= self.stack: return Raise(self.pip + 2 * chips_to_add + random_addition) else: return Raise(self.stack + self.pip) else: if value_bet >= self.stack: if value_bet <= chips_to_add or self.slowplay_flag: #defense return Call() else: return Raise(self.stack + self.pip) elif value_bet >= 2 * chips_to_add: if self.slowplay_flag: #defense against bleeding return Call() else: return Raise(value_bet + self.pip) elif value_call >= chips_to_add: return Call() else: return Fold() elif isinstance(action, Call): #only options are calling and folding if value_call >= chips_to_add: return Call() else: return Fold() # if something screws up, try checking return Check()