Exemplo n.º 1
0
  def save_modeling(self, num_players, shared_cards):
    
    hand = hand_strength.HandStrength(num_players)
    strength = hand.calculate(self.cards, shared_cards)

    # in form of [[context, action], [context, action], ... ] and player, strength
    db.insert_data(self.modeling, self.name, strength)
Exemplo n.º 2
0
    def take_action(self, highest_bet, pot, players, position, shared_cards,
                    state, total_raises, active_players):
        if len(shared_cards) < 1:  # pre-flop

            # Fetch information from stored data for rollout simulations.

            strength = fetch_rollout_data(players, self.cards)

        else:
            # Use hand strength calculations
            hand = hand_strength.HandStrength(players)
            strength = hand.calculate(self.cards, shared_cards)

        # We now have strength. Use this to take actions.

        if not strength:
            strength = 0

        if (self.play_style == "loose_aggressive"):
            return self.take_loose_aggressive_action(highest_bet, pot, players,
                                                     position, shared_cards,
                                                     state, total_raises,
                                                     strength)
        else:
            return self.take_tight_passive_action(highest_bet, pot, players,
                                                  position, shared_cards,
                                                  state, total_raises,
                                                  strength)
Exemplo n.º 3
0
    def take_action(self, highest_bet, pot, players, position, shared_cards,
                    state, total_raises, active_players):
        # generate_context(betting_round, players_remaining, num_raises, pot_odds)
        # get_hand_strength(context, player, action)
        # self.calculated_opponent_models

        pot_odds = (float(highest_bet) / (float(highest_bet) + float(pot)))
        context = player.db.generate_context(state, players, total_raises,
                                             pot_odds)

        in_checker = [
        ]  # array used to double check that the players haven't dropped out (folded)

        # Now we can use context to check all players
        # Iterate over the players who has already played their hand this round and overwrite the previous value.
        for p in active_players:
            if p == None:  # continue next iteration if player not active
                continue

            if p.name == self.name:  #check for self if so drop out
                break

            in_checker.append(p.name)
            self.calculated_opponent_models[
                p.name] = player.db.get_hand_strength(context, p.name,
                                                      p.last_action)

        # Remove all models of folded players
        for k, v in self.calculated_opponent_models.copy().items():
            if k not in in_checker:
                del self.calculated_opponent_models[k]

        # Now we can use the self.calculated_opponent_models dictionary to
        # see if any of the players have a exceptionally good hand

        # Find the highest strength of an opponent.
        highest_strength = 0
        for k, s in self.calculated_opponent_models.items():
            if s > highest_strength and k != self.name:
                highest_strength = s

        # Begin intelligent behaviour....
        if state == 1:  # Pre-flop
            # Take hand strength into account?
            # Fetch information from stored data for rollout simulations.

            strength = phase2.fetch_rollout_data(players, self.cards)

        else:  # post-flop
            # Use hand strength calculations

            hand = hand_strength.HandStrength(players)
            strength = hand.calculate(self.cards, shared_cards)

        # We now have strength. Use this to take actions.
        if not strength:
            strength = 0

        if (self.play_style == "loose_aggressive"):
            return self.take_loose_aggressive_action(highest_bet, pot, players,
                                                     position, shared_cards,
                                                     state, total_raises,
                                                     strength,
                                                     highest_strength)
        else:
            return self.take_tight_passive_action(highest_bet, pot, players,
                                                  position, shared_cards,
                                                  state, total_raises,
                                                  strength, highest_strength)