コード例 #1
0
    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
        """

        if not self.board:
            print "preflop"
            return self.preflop_strategy()
        elif self.board:
            if len(self.board) == 3:
                print "flopped"
                return self.flop_strategy()
            elif len(self.board) == 4:
                # replace with your turn logic
                print "turn"
                return self.turn_strategy()
            elif len(self.board) == 5:
                # replace with your river logic
                print "river"
                return self.river_strategy()

        # this is the default action, in case you forget to return something.
        # it's better than folding
        return Check()
コード例 #2
0
ファイル: mastermonte.py プロジェクト: afcarl/notpoker
    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()
コード例 #3
0
    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
        """

        if not self.board.board:
            hand_data = HandEvaluator.evaluate_preflop_hand(self.hand)
        elif self.board:
            hand_data = HandEvaluator.evaluate_hand(self.board.cards + list(self.hand))
            if len(self.board.board) == 3:
                return Check()
            elif len(self.board.board) == 4:
                return Check()
            elif len(self.board.board) == 5:
                return Check()
        
        # always return Check() as last resort, because it beats Fold()
        return Check()
コード例 #4
0
    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()
コード例 #5
0
    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
        """

        if self.hands_played != self.hand_counter:
            self.hand_counter = self.hands_played
            self.percentiles = {}
            self.slowplay_flag = False

        # see other templates for a modular way of determining an action
        if not self.board.board:
            if 'preflop' not in self.percentiles:
                self.percentiles['preflop'] = HandEvaluator.evaluate_hand(
                    self.hand)
                self.played_this_street = 0
                if self.button:
                    self.opponent_previous_pip = 2
                else:
                    self.opponent_previous_pip = 1
            self.played_this_street += 1
            return self.strategy(2, self.percentiles['preflop'])
        elif self.board:
            if len(self.board.board) == 3:
                if 'flop' not in self.percentiles:
                    self.percentiles['flop'] = HandEvaluator.evaluate_hand(
                        self.hand, self.board.cards)
                    self.played_this_street = 0
                    self.opponent_previous_pip = 0
                self.played_this_street += 1
                return self.strategy(3, self.percentiles['flop'])
            elif len(self.board.board) == 4:
                if 'turn' not in self.percentiles:
                    self.percentiles['turn'] = HandEvaluator.evaluate_hand(
                        self.hand, self.board.cards)
                    self.played_this_street = 0
                    self.opponent_previous_pip = 0
                self.played_this_street += 1
                return self.strategy(4, self.percentiles['turn'])
            elif len(self.board.board) == 5:
                if 'river' not in self.percentiles:
                    self.percentiles['river'] = HandEvaluator.evaluate_hand(
                        self.hand, self.board.cards)
                    self.played_this_street = 0
                    self.opponent_previous_pip = 0
                self.played_this_street += 1
                return self.strategy(5, self.percentiles['river'])

        return Check()
コード例 #6
0
    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
        """

        if self.hands_played != self.hand_counter:
            self.hand_counter = self.hands_played
            # reset stuff
            self.percentiles = {}

        # self.last contains the last hand
        # define self.hand_history as [] in __init__
        # or you can't append to this list
        # self.hand_history.append(self.last)

        # see other templates for a modular way of determining an action

        if not self.board.board:
            self.percentiles['preflop'] = HandEvaluator.evaluate_hand(
                self.hand, self.board.cards)
            return self.preflop_strategy()
        elif self.board:
            if len(self.board.board) == 3:
                self.percentiles['flop'] = HandEvaluator.evaluate_hand(
                    self.hand, self.board.cards)
                return Check()
            elif len(self.board.board) == 4:
                self.percentiles['turn'] = HandEvaluator.evaluate_hand(
                    self.hand, self.board.cards)
                return Check()
            elif len(self.board.board) == 5:
                self.percentiles['river'] = HandEvaluator.evaluate_hand(
                    self.hand, self.board.cards)
                return Check()

        return Check()
コード例 #7
0
ファイル: template.py プロジェクト: afcarl/notpoker
    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()
コード例 #8
0
ファイル: mastermonte.py プロジェクト: afcarl/notpoker
    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
        """

        if not self.board.board:
            #self.evaluate_opponent()
            return self.preflop_strategy()
        elif self.board:
            if len(self.board.board) == 3:
                return self.flop_strategy()
            elif len(self.board.board) == 4:
                return self.turn_strategy()
            elif len(self.board.board) == 5:
                return self.river_strategy()

        # this is the default action, in case you forget to return something.
        # it's better than folding
        return Check()
コード例 #9
0
    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
        """

        if self.debug:
            print(self.name)
            print('self.hand', self.hand)
            print('self.board', self.board)
            print('self.stack', self.stack)
            print('self.pip', self.pip)
            print('self.button', self.button)
            print('self.opponent', self.opponent)
            print('self.bb', self.bb)
            print('self.sb', self.sb)
            print('self.hands_played', self.hands_played)
            print('self.legal', self.legal)
            print('self.pot', self.pot)

        if self.hands_played != self.hand_counter:
            self.hand_counter = self.hands_played
            # reset stuff
            self.percentiles = {}
            self.opponent_percentiles = {}
            #self.evaluate_opponent()

        # self.last contains the last hand
        # define self.hand_history as [] in __init__
        # or you can't append to this list
        # self.hand_history.append(self.last)

        # see other templates for a modular way of determining an action
        if not self.board.board:
            if 'preflop' not in self.percentiles:
                self.percentiles['preflop'] = HandEvaluator.evaluate_hand(
                    self.hand)
                if self.debug:
                    print('preflop percentile ', self.percentiles['preflop'])
                self.opponent_previous_pip = 0
            return self.strategy(2, self.percentiles['preflop'])
        elif self.board:
            if len(self.board.board) == 3:
                if 'flop' not in self.percentiles:
                    self.percentiles['flop'] = HandEvaluator.evaluate_hand(
                        self.hand, self.board.cards)
                    if self.debug:
                        print('flop percentile ', self.percentiles['flop'])
                        self.opponent_previous_pip = 0
                return self.strategy(3, self.percentiles['flop'])
            elif len(self.board.board) == 4:
                if 'turn' not in self.percentiles:
                    self.percentiles['turn'] = HandEvaluator.evaluate_hand(
                        self.hand, self.board.cards)
                    if self.debug:
                        print('turn percentile ', self.percentiles['turn'])
                        self.opponent_previous_pip = 0
                return self.strategy(4, self.percentiles['turn'])
            elif len(self.board.board) == 5:
                if 'river' not in self.percentiles:
                    self.percentiles['river'] = HandEvaluator.evaluate_hand(
                        self.hand, self.board.cards)
                    if self.debug:
                        print('river percentile ', self.percentiles['river'])
                        self.opponent_previous_pip = 0
                return self.strategy(5, self.percentiles['river'])

        if self.debug:
            print('Something screwed up, so we are checking (1)')
            ok = raw_input('press enter\n')
        return Check()
コード例 #10
0
    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()
コード例 #11
0
    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()
コード例 #12
0
    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()
コード例 #13
0
ファイル: zachbot.py プロジェクト: afcarl/notpoker
    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()
コード例 #14
0
 def flop_strategy(self):
     """
     Returns an action after the flop, based on the table and the player
     """
     return Check()
コード例 #15
0
 def preflop_strategy(self):
     """
     Returns an action before the flop, based on the table and the player
     """
     return Check()
コード例 #16
0
    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()
コード例 #17
0
 def river_strategy(self):
     """
     Returns an action after the river, based on the table and the player
     """
     return Check()