def declare_action( self, valid_actions: List[Dict[str, Union[int, str]]], hole_card: List[str], round_state: Dict[str, Union[int, str, List, Dict]] ) -> Tuple[Union[int, str], Union[int, str]]: """ Define what action the player should execute. :param valid_actions: List of dictionary containing valid actions the player can execute. :param hole_card: Cards in possession of the player encoded as a list of strings. :param round_state: Dictionary containing relevant information and history of the game. :return: action: str specifying action type. amount: int action argument. """ nb_player = len(round_state['seats']) community_card = round_state['community_card'] win_rate = estimate_hole_card_win_rate( nb_simulation=NB_SIMULATION, nb_player=nb_player, hole_card=gen_cards(hole_card), community_card=gen_cards(community_card)) if win_rate >= 1.0 / nb_player: action = valid_actions[2] # fetch RAISE action info amount = action["amount"] action['amount'] = random.randint( amount["min"], max(amount["min"], amount["max"])) elif win_rate >= .1: action = valid_actions[1] # fetch CALL action info else: action = valid_actions[0] # fetch FOLD action info return action['action'], action['amount']
def declare_action(self, valid_actions, hole_card, round_state): self.rng = random.randint(0, 10) community_card = round_state['community_card'] self.win_rate = estimate_hole_card_win_rate( nb_simulation=NB_SIMULATION, nb_player=2, hole_card=gen_cards(hole_card), community_card=gen_cards(community_card)) act = 0 act += self.coeff[0] * self.normalize(self.curr_round, 0, 1000) act += self.coeff[1] * self.normalize(self.curr_money_diff, -10000, 10000) act += self.coeff[2] * self.normalize(self.curr_street, 1, 4) act += self.coeff[3] * self.normalize(self.rng, 0, 10) act += self.coeff[4] * self.normalize(self.win_rate, 0, 1) if act > 0.33 and len(valid_actions) == 3: action = valid_actions[2] elif act > -0.33: action = valid_actions[1] else: action = valid_actions[0] #print(action['action']) return action['action'] '''
def estimate_win_rate(nb_simulation, nb_player, hole_card, community_card=None): if not community_card: community_card = [] # Make lists of Card objects out of the list of cards community_card = gen_cards(community_card) hole_card = gen_cards(hole_card) # Estimate the win count by doing a Monte Carlo simulation win_count = sum([montecarlo_simulation(nb_player, hole_card, community_card) for _ in range(nb_simulation)]) return 1.0 * win_count / nb_simulation
def declare_action(self, valid_actions, hole_card, round_state): community_card = round_state['community_card'] win_rate = estimate_hole_card_win_rate( nb_simulation=NB_SIMULATION, nb_player=self.nb_player, hole_card=gen_cards(hole_card), community_card=gen_cards(community_card) ) if win_rate >= 1.0 / self.nb_player: action = valid_actions[1] # fetch CALL action info else: action = valid_actions[0] # fetch FOLD action info return action['action'], action['amount']
def _setup_game_state(self, round_state, my_hole_card): game_state = restore_game_state(round_state) game_state['table'].deck.shuffle() player_uuids = [player_info['uuid'] for player_info in round_state['seats']] for uuid in player_uuids: if uuid == self.uuid: game_state = attach_hole_card(game_state, uuid, gen_cards(my_hole_card)) # attach my holecard else: game_state = attach_hole_card_from_deck(game_state, uuid) # attach opponents holecard at random return game_state