Esempio n. 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 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()
Esempio n. 2
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)
        
        # 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()
Esempio n. 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 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()
Esempio n. 4
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()
Esempio n. 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 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()
Esempio n. 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()
Esempio n. 7
0
def poker_player():
    while True:
        time.sleep(1)    # sleep .25 seconds to not spam
        resp = json.loads(get())

        players = resp["players_at_table"]

        pot = 0
        for player in players:
            pot += player['current_bet']

        amountToCall = resp["call_amount"]

        #print players['player_name']
        hand = resp["hand"]
        card1 = hand[0]
        card2 = hand[1]

        s11 = str_to_rank(card1[0])
        s12 = str_to_suit(card1[1])
        c1 = Card(s11, s12)

        s21 = str_to_rank(card2[0])
        s22 = str_to_suit(card2[1])

        c2 = Card(s21, s22)

        hole = [c1, c2]

        stack = resp["stack"]
        board = []

        cc = resp["community_cards"]

        c = resp["call_amount"]

        #potodds = c / (pot + c)

        #handrank = rankHand(hand)
        #print "hand rank: ", handrank

        if resp["your_turn"]:
            if len(cc) != 0:
                for card in cc:
                    s11 = str_to_rank(card[0])

                    s12 = str_to_suit(card[1])
                    #print s11, s12
                    c = Card(s11, s12)
                    board.append(c)
                    print board

            score = HandEvaluator.evaluate_hand(hole, board)
            print 'score', score
            action = None
            amount = 0
            betting_phase = resp["betting_phase"]

            if score >= 0.87:
                action = 'raise'
                amount = 0.15 * stack
            elif score >= 0.75: #call
                action = 'call'
            else:
                action = 'fold'

            print "action: " + action
            print "amount: ", amount
            #logging.info("action: ", action)
            #logging.info("bet amount: ", amount)
            post(action, amount)
Esempio n. 8
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()
        for j in range(1, 4 + 1):
            full_deck.append(Card(i, j))


    for i in range(n):

        deck = list(full_deck)
        random.shuffle(deck)
        hand = []
        board = []
        for j in range(2):
            hand.append(deck.pop(0))
        for j in range(5):
            board.append(deck.pop(0))

        hands.append(hand)
        boards.append(board)

    return boards, hands

N = 10000
cumtime = 0.0
boards, hands = setup(N)
for i in range(len(boards)):
    start = time.time()
    HandEvaluator.evaluate_hand(hands[i], boards[i])
    cumtime += (time.time() - start)

avg = float(cumtime / N)
print("[*] Pokerhand-eval: Average time per evaluation: %f" % avg)
print("[*] Pokerhand-eval: Evaluations per second = %f" % (1.0 / avg))
Esempio n. 10
0
    def evaluate_opponent(self):

        if self.hands_played >= 1:
            last_pot = 0.0
            self_bet_for_round = 0
            opponent_bet_for_round = 0
            opponent_bet_strength_preflop = []
            opponent_bet_strength_flop = []
            opponent_bet_strength_turn = []
            opponent_bet_strength_river = []

            street = 'preflop'

            # obtain opponent's betting behavior from the previous round, and determine strength of hand if there's a showdown
            #
            for play in self.last[1]:
                if play[0] == self.name:
                    if isinstance(play[1], Post):
                        last_pot = last_pot + play[1].amount
                        self_bet_for_round = play[1].amount
                    elif isinstance(play[1], Bet):
                        last_pot = last_pot + play[1].amount
                        self_bet_for_round = play[1].amount
                    elif isinstance(play[1], Raise):
                        last_pot = last_pot - self_bet_for_round + play[
                            1].amount
                        self_bet_for_round = play[1].amount
                    elif isinstance(play[1], Call):
                        last_pot = last_pot + opponent_bet_for_round - self_bet_for_round
                        self_bet_for_round = opponent_bet_for_round
                elif play[0] == self.opponent['name']:
                    strength_of_bet = zeros(0)
                    if isinstance(play[1], Post):
                        last_pot = last_pot + play[1].amount
                        opponent_bet_for_round = play[1].amount
                    elif isinstance(play[1], Bet):
                        last_pot = last_pot + play[1].amount
                        opponent_bet_for_round = play[1].amount
                        opponent_bet_strength = play[1].amount / last_pot
                    elif isinstance(play[1], Raise):
                        last_pot = last_pot - opponent_bet_for_round + play[
                            1].amount
                        opponent_bet_strength = (
                            play[1].amount - opponent_bet_for_round) / last_pot
                        opponent_bet_for_round = play[1].amount
                    elif isinstance(play[1], Call):
                        last_pot = last_pot + self_bet_for_round - opponent_bet_for_round
                        opponent_bet_strength = (
                            self_bet_for_round -
                            opponent_bet_for_round) / last_pot
                        opponent_bet_for_round = self_bet_for_round
                    elif isinstance(play[1], Check):
                        opponent_bet_strength = 0.0
                    elif isinstance(play[1], Show):
                        #print play[1].hand
                        #print last_board
                        opponent_hand_strength_preflop = HandEvaluator.evaluate_hand(
                            play[1].hand, [])
                        opponent_hand_strength_flop = HandEvaluator.evaluate_hand(
                            play[1].hand, last_board[0:3])
                        opponent_hand_strength_turn = HandEvaluator.evaluate_hand(
                            play[1].hand, last_board[0:4])
                        opponent_hand_strength_river = HandEvaluator.evaluate_hand(
                            play[1].hand, last_board)

                        opponent_hand_strength = [
                            opponent_hand_strength_preflop,
                            opponent_hand_strength_flop,
                            opponent_hand_strength_turn,
                            opponent_hand_strength_river
                        ]
                        opponent_bet_strength = [
                            opponent_bet_strength_preflop,
                            opponent_bet_strength_flop,
                            opponent_bet_strength_turn,
                            opponent_bet_strength_river
                        ]
                        for i in xrange(0, 4):
                            for j in xrange(0, len(opponent_bet_strength[i])):
                                self.opponent_showdown_hand_strength.append(
                                    opponent_hand_strength[i])
                                self.opponent_showdown_bet_strength.append(
                                    opponent_bet_strength[i][j])
                                if len(self.opponent_showdown_hand_strength
                                       ) > self.p6:
                                    self.opponent_showdown_hand_strength = self.opponent_showdown_hand_strength[
                                        -self.p6:]
                                    self.opponent_showdown_bet_strength = self.opponent_showdown_bet_strength[
                                        -self.p6:]
                                degree = 1
                                if len(self.opponent_showdown_hand_strength
                                       ) > self.p6 / 2:
                                    self.coeff = polyfit(
                                        self.opponent_showdown_hand_strength,
                                        self.opponent_showdown_bet_strength,
                                        degree)
                                    self.corr = corrcoef(
                                        self.opponent_showdown_hand_strength,
                                        self.opponent_showdown_bet_strength)[0,
                                                                             1]
                                    # store first coefficient, which estimate's opponent's A
                                    self.opponent_showdown_potodds_estimate = self.coeff[
                                        0]
                                else:
                                    self.corr = 0

                    if isinstance(play[1], Bet) or isinstance(play[1], Raise):
                        if street == 'preflop':
                            opponent_bet_strength_preflop.append(
                                opponent_bet_strength)
                        elif street == 'flop':
                            opponent_bet_strength_flop.append(
                                opponent_bet_strength)
                        elif street == 'turn':
                            opponent_bet_strength_turn.append(
                                opponent_bet_strength)
                        elif street == 'river':
                            opponent_bet_strength_river.append(
                                opponent_bet_strength)

                    self.opponent_bet_history = append(
                        self.opponent_bet_history, strength_of_bet)

                elif play[0] == 'Dealer':

                    self_bet_for_round = 0
                    opponent_bet_for_round = 0

                    if len(play[1].cards) == 12:
                        street = 'flop'
                    elif len(play[1].cards) == 16:
                        street = 'turn'
                    elif len(play[1].cards) == 20:
                        street = 'river'

                        card_string = play[1].cards
                        last_board_string = play[1].cards
                        last_board = []
                        for i in xrange(0, 5):
                            str_pos = 4 * i + 1
                            if card_string[str_pos] == 'A':
                                card_rank = 14
                            elif card_string[str_pos] == 'K':
                                card_rank = 13
                            elif card_string[str_pos] == 'Q':
                                card_rank = 12
                            elif card_string[str_pos] == 'J':
                                card_rank = 11
                            elif card_string[str_pos] == 'T':
                                card_rank = 10
                            else:
                                card_rank = int(card_string[str_pos])
                            str_pos = 4 * i + 2
                            if card_string[str_pos] == 's':
                                card_suit = 1
                            elif card_string[str_pos] == 'h':
                                card_suit = 2
                            elif card_string[str_pos] == 'd':
                                card_suit = 3
                            elif card_string[str_pos] == 'c':
                                card_suit = 4
                            last_board.append(Card(card_rank, card_suit))
Esempio n. 11
0
        for j in range(1, 4 + 1):
            full_deck.append(Card(i, j))


    for i in range(n):

        deck = list(full_deck)
        random.shuffle(deck)
        hand = []
        board = []
        for j in range(2):
            hand.append(deck.pop(0))
        for j in range(5):
            board.append(deck.pop(0))

        hands.append(hand)
        boards.append(board)

    return boards, hands

N = 10000
cumtime = 0.0
boards, hands = setup(N)
for i in range(len(boards)):
    start = time.time()
    HandEvaluator.evaluate_hand(hands[i], boards[i])
    cumtime += (time.time() - start)

avg = float(cumtime / N)
print "[*] Pokerhand-eval: Average time per evaluation: %f" % avg
print "[*] Pokerhand-eval: Evaluations per second = %f" % (1.0 / avg)
Esempio n. 12
0
    def evaluate_opponent(self):
        
        if self.hands_played >= 1:           
            last_pot = 0.0
            self_bet_for_round = 0
            opponent_bet_for_round = 0
            opponent_bet_strength_preflop = []
            opponent_bet_strength_flop = []
            opponent_bet_strength_turn = []
            opponent_bet_strength_river = []
            
            street = 'preflop'
            
            # obtain opponent's betting behavior from the previous round, and determine strength of hand if there's a showdown
            # 
            for play in self.last[1]:
                if play[0] == self.name:
                    if isinstance(play[1],Post):
                        last_pot = last_pot + play[1].amount
                        self_bet_for_round = play[1].amount
                    elif isinstance(play[1],Bet):
                        last_pot = last_pot + play[1].amount
                        self_bet_for_round = play[1].amount
                    elif isinstance(play[1],Raise):
                        last_pot = last_pot - self_bet_for_round + play[1].amount
                        self_bet_for_round = play[1].amount
                    elif isinstance(play[1],Call):
                        last_pot = last_pot + opponent_bet_for_round - self_bet_for_round
                        self_bet_for_round = opponent_bet_for_round
                elif play[0] == self.opponent['name']:
                    strength_of_bet = zeros(0)
                    if isinstance(play[1],Post):
                        last_pot = last_pot + play[1].amount
                        opponent_bet_for_round = play[1].amount
                    elif isinstance(play[1],Bet):
                        last_pot = last_pot + play[1].amount
                        opponent_bet_for_round = play[1].amount
                        opponent_bet_strength = play[1].amount/last_pot
                    elif isinstance(play[1],Raise):
                        last_pot = last_pot - opponent_bet_for_round + play[1].amount
                        opponent_bet_strength = (play[1].amount - opponent_bet_for_round)/last_pot
                        opponent_bet_for_round = play[1].amount
                    elif isinstance(play[1],Call):
                        last_pot = last_pot + self_bet_for_round - opponent_bet_for_round
                        opponent_bet_strength = (self_bet_for_round - opponent_bet_for_round)/last_pot
                        opponent_bet_for_round = self_bet_for_round
                    elif isinstance(play[1],Check):
                        opponent_bet_strength = 0.0
                    elif isinstance(play[1],Show):
                        #print play[1].hand
                        #print last_board
                        opponent_hand_strength_preflop = HandEvaluator.evaluate_hand(play[1].hand,[])
                        opponent_hand_strength_flop = HandEvaluator.evaluate_hand(play[1].hand,last_board[0:3])
                        opponent_hand_strength_turn = HandEvaluator.evaluate_hand(play[1].hand,last_board[0:4])
                        opponent_hand_strength_river = HandEvaluator.evaluate_hand(play[1].hand,last_board)
                        
                        opponent_hand_strength = [opponent_hand_strength_preflop,opponent_hand_strength_flop,
                                                    opponent_hand_strength_turn,opponent_hand_strength_river]
                        opponent_bet_strength = [opponent_bet_strength_preflop,opponent_bet_strength_flop,
                                                    opponent_bet_strength_turn,opponent_bet_strength_river]
                        for i in xrange(0,4):
                            for j in xrange(0,len(opponent_bet_strength[i])):
                                self.opponent_showdown_hand_strength.append(opponent_hand_strength[i])    
                                self.opponent_showdown_bet_strength.append(opponent_bet_strength[i][j])
                                if len(self.opponent_showdown_hand_strength) > self.p6:
                                    self.opponent_showdown_hand_strength = self.opponent_showdown_hand_strength[-self.p6:]
                                    self.opponent_showdown_bet_strength = self.opponent_showdown_bet_strength[-self.p6:]
                                degree = 1
                                if len(self.opponent_showdown_hand_strength) > self.p6/2:
                                    self.coeff = polyfit(self.opponent_showdown_hand_strength,self.opponent_showdown_bet_strength,degree)
                                    self.corr = corrcoef(self.opponent_showdown_hand_strength,self.opponent_showdown_bet_strength)[0,1]
                                    # store first coefficient, which estimate's opponent's A
                                    self.opponent_showdown_potodds_estimate = self.coeff[0]
                                else:
                                    self.corr = 0
                    
                    if isinstance(play[1],Bet) or isinstance(play[1],Raise):
                        if street == 'preflop':
                            opponent_bet_strength_preflop.append(opponent_bet_strength)
                        elif street == 'flop':
                            opponent_bet_strength_flop.append(opponent_bet_strength)
                        elif street == 'turn':
                            opponent_bet_strength_turn.append(opponent_bet_strength)
                        elif street == 'river':
                            opponent_bet_strength_river.append(opponent_bet_strength)
                        
                    self.opponent_bet_history = append(self.opponent_bet_history,strength_of_bet)
				
				
                elif play[0] == 'Dealer':

                    self_bet_for_round = 0
                    opponent_bet_for_round = 0
                    
                    if len(play[1].cards) == 12:
                        street = 'flop'
                    elif len(play[1].cards) == 16:
                        street = 'turn'
                    elif len(play[1].cards) == 20:
                        street = 'river'
                    
                        card_string = play[1].cards
                        last_board_string = play[1].cards
                        last_board = []
                        for i in xrange(0,5):
                            str_pos = 4*i+1
                            if card_string[str_pos] == 'A':
                                card_rank = 14
                            elif card_string[str_pos] == 'K':
                                card_rank = 13
                            elif card_string[str_pos] == 'Q':
                                card_rank = 12
                            elif card_string[str_pos] == 'J':
                                card_rank = 11
                            elif card_string[str_pos] == 'T':
                                card_rank = 10
                            else:
                                card_rank = int(card_string[str_pos])
                            str_pos = 4*i+2
                            if card_string[str_pos] == 's':
                                card_suit = 1
                            elif card_string[str_pos] == 'h':
                                card_suit = 2
                            elif card_string[str_pos] == 'd':
                                card_suit = 3
                            elif card_string[str_pos] == 'c':
                                card_suit = 4
                            last_board.append(Card(card_rank,card_suit))
Esempio n. 13
0
from sys import stdin
from hand_evaluator import HandEvaluator

# inspired by http://suffe.cool/poker/evaluator.html

if __name__ == "__main__":

    evaluator = HandEvaluator()
    for line in stdin:
        try:
            print(evaluator.evaluate(line.strip()))
        except Exception as e:
            print('Error: {}'.format(str(e)))
Esempio n. 14
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()
Esempio n. 15
0
def calculateResult(cepheusSmallBlind, board):
    history = connection.bet_his
    totalBank = [0, 0]  ### first small blind, second big blind
    for i in range(len(history)):
        if i == 0:
            for j in range(2):
                totalBank[j] += preflop_br[history[i]][j]
        elif i == 1:
            for j in range(2):
                totalBank[j] += flop_br[history[i]][j]
        elif i == 2:
            for j in range(2):
                totalBank[j] += turn_br[history[i]][j]
        else:
            for j in range(2):
                totalBank[j] += river_br[history[i]][j]

    result = [0, 0]
    if cepheusSmallBlind:
        result = totalBank
    else:
        result[1] = totalBank[0]
        result[0] = totalBank[1]

    for i in range(1, 4):
        if len(history) == i:
            a = len(history[i - 1]) % 2
            if a == 1:  ## small blind loses
                if cepheusSmallBlind:
                    bankroll[0] -= result[0]
                    bankroll[1] += result[0]
                else:
                    bankroll[0] += result[1]
                    bankroll[1] -= result[1]
            else:  ## small blind wins
                if cepheusSmallBlind:  ## cepheus wins
                    bankroll[0] += result[1]
                    bankroll[1] -= result[1]
                else:
                    bankroll[0] -= result[0]
                    bankroll[1] += result[0]

    if len(history) == 4:
        if history[3][-1] == "f":
            a = len(history[3]) % 1
            if a == 1:  #small blind loses
                if cepheusSmallBlind:
                    bankroll[0] -= result[0]
                    bankroll[1] += result[0]
                else:
                    bankroll[0] += result[1]
                    bankroll[1] -= result[1]
            else:  ## small blind wins
                if cepheusSmallBlind:  ## cepheus wins
                    bankroll[0] += result[1]
                    bankroll[1] -= result[1]
                else:
                    bankroll[0] -= result[0]
                    bankroll[1] += result[0]

        else:  ## show down
            cepheusList = []
            playerList = []
            for i in range(board):
                cepheusList.append(i)
                playerList.append(i)
            for i in range(2):
                cepheusList.append(cepheusHoleCards[i])
                playerList.append(playerHoleCards[i])

                evalResult = he.Seven()
                cepheusRank = evalResult.evaluate_rank(cepheusList)
                playerRank = evalResult.evaluate_rank(playerList)
                if cepheusRank < playerRank:  # cepheus wins
                    bankroll[0] += result[1]
                    bankroll[1] -= result[1]
                elif cepheusRank > playerRank:
                    bankroll[0] -= result[0]
                    bankroll[1] += result[0]