def _print_state(state, action_record): ''' Print out the state Args: state (dict): A dictionary of the raw state action_record (list): A list of the historical actions ''' _action_list = [] for i in range(1, len(action_record) + 1): if action_record[-i][0] == state['current_player']: break _action_list.insert(0, action_record[-i]) for pair in _action_list: print('>> Player', pair[0], 'chooses', pair[1]) print('\n=============== Community Card ===============') print_card(state['public_card']) print('=============== Your Hand ===============') print_card(state['hand']) print('=============== Chips ===============') print('Yours: ', end='') for _ in range(state['my_chips']): print('+', end='') print('') for i in range(len(state['all_chips'])): if i != state['current_player']: print('Agent {}: '.format(i), end='') for _ in range(state['all_chips'][i]): print('+', end='') print('\n=========== Actions You Can Choose ===========') print(', '.join([ str(index) + ': ' + action for index, action in enumerate(state['legal_actions']) ])) print('')
def play(env): while (True): print(">> Start a new game") trajectories, payoffs = env.run(is_training=False) print(trajectories) # If the human does not take the final action, we need to # print other players action if len(trajectories[0]) != 0: final_state = trajectories[0][-1][-2] action_record = final_state['action_record'] _action_list = [] for i in range(1, len(action_record)+1): _action_list.insert(0, action_record[-i]) for pair in _action_list: print('>> Player', pair[0], 'chooses', pair[1]) # Let's take a look at what the agent card is print('============= DQN ============') print_card(env.get_perfect_information()['hand_cards'][1]) print('=============== Result ===============') if payoffs[0] > 0: print('You win {} chips!'.format(payoffs[0])) elif payoffs[0] == 0: print('It is a tie.') else: print('You lose {} chips!'.format(-payoffs[0])) print('') log(payoffs[0]) input("Press any key to continue...")
def _print_state(state, raw_legal_actions, action_record): ''' Print out the state Args: state (dict): A dictionary of the raw state action_record (list): A list of the each player's historical actions ''' _action_list = [] for i in range(1, len(action_record) + 1): _action_list.insert(0, action_record[-i]) for pair in _action_list: print('>> Player', pair[0], 'chooses', pair[1]) print('\n============= Dealer Hand ===============') print_card(state['dealer hand']) num_player = len(state) - 3 for i in range(num_player): print('=============== Player {} Hand ==============='.format(i)) print_card(state['player' + str(i) + ' hand']) print('\n=========== Actions You Can Choose ===========') print(', '.join([ str(index) + ': ' + action for index, action in enumerate(raw_legal_actions) ])) print('')
def _print_state(state, action_record): ''' Print out the state Args: state (dict): A dictionary of the raw state action_record (list): A list of the historical actions ''' _action_list = [] for i in range(1, len(action_record) + 1): if action_record[-i][0] == state['current_player']: break _action_list.insert(0, action_record[-i]) for pair in _action_list: print('>> Player', pair[0], 'chooses', pair[1]) print('\n=============== Community Card ===============') print_card(state['public_cards']) print('============= Player', state["current_player"], '- Hand =============') print_card(state['hand']) print('=============== Chips ===============') print('In Pot:', state["pot"]) print('Remaining:', state["stakes"]) print('\n=========== Actions You Can Choose ===========') print(', '.join([ str(index) + ': ' + str(action) for index, action in enumerate(state['legal_actions']) ])) print('') print(state)
def render(self, mode='human'): for player in self.possible_agents: state = self.env.game.get_state(self._name_to_int(player)) print("\n=============== {}'s Hand ===============".format(player)) print_card(state['hand']) print("\n{}'s Chips: {}".format(player, state['my_chips'])) print('\n================= Public Cards =================') print_card(state['public_cards']) if state['public_cards'] else print('No public cards.') print('\n')
def render(self, mode='human'): for player in self.agents: state = self.env.game.round.players[self._name_to_int(player)].hand print("\n===== {}'s Hand =====".format(player)) print_card([c.__str__()[::-1] for c in state]) state = self.env.game.get_state(0) print("\n==== Top Discarded Card ====") print_card([c.__str__() for c in state['top_discard']] if state else None) print('\n')
def render(self, mode="human"): for player in self.possible_agents: state = self.env.game.round.players[self._name_to_int(player)].hand print("\n===== {}'s Hand =====".format(player)) print_card([c.__str__()[::-1] for c in state]) state = self.env.game.get_state(0) print("\n==== Top Discarded Card ====") print_card([c.__str__() for c in state["discard_pile"][-1]] if state else None) print("\n")
def game_over_print(self, win_condition, winners, payoffs): if win_condition: for i in range(self.num_players): player_id = self.players[i].get_player_id() hand = self.players[i].get_hand() print("Player {}:".format(player_id)) print(print_card(hand)) print("Public Cards:") print(print_card(self.public_cards)) print("The winner is Player {}. It wins {} chips.".format( np.where(np.array(winners) == 1)[0], max(payoffs)))
def _print_state(state, action_record): ''' Print out the state Args: state (dict): A dictionary of the raw state action_record (list): A list of the historical actions ''' _action_list = [] for i in range(1, len(action_record)+1): if action_record[-i][0] == state['current_player']: break _action_list.insert(0, action_record[-i]) for pair in _action_list: print('>> Player', pair[0], 'chooses', pair[1]) print('\n=============== Community Card ===============') print_card(state['public_cards']) print('============= Player',state["current_player"],'- Hand =============')
def test_print_cards(self): self.assertEqual(len(elegent_form('S9')), 2) self.assertEqual(len(elegent_form('ST')), 3) print_card(None) print_card('S9') print_card('ST')
_action_list = [] for i in range(num_players): final_state.append(trajectories[i][-1][-2]) state.append(final_state[i]['raw_obs']) action_record.append(final_state[i]['action_record']) for i in range(1, len(action_record) + 1): _action_list.insert(0, action_record[-i]) for pair in _action_list[0]: print('>> Player', pair[0], 'chooses', pair[1]) # Let's take a look at what the agent card is print('=============== Dealer hand ===============') print_card(state[0]['state'][1]) for i in range(num_players): print('=============== Player {} Hand ==============='.format(i)) print_card(state[i]['state'][0]) print('=============== Result ===============') for i in range(num_players): if payoffs[i] == 1: print('Player {} win {} chip!'.format(i, payoffs[i])) elif payoffs[i] == 0: print('Player {} is tie'.format(i)) else: print('Player {} lose {} chip!'.format(i, -payoffs[i])) print('')
# If the human does not take the final action, we need to # print other players action if len(trajectories[0]) != 0: final_state = trajectories[0][-1] action_record = final_state['action_record'] state = final_state['raw_obs'] _action_list = [] for i in range(1, len(action_record) + 1): """ if action_record[-i][0] == state['current_player']: break """ _action_list.insert(0, action_record[-i]) for pair in _action_list: print('>> Player', pair[0], 'chooses', pair[1]) # Let's take a look at what the agent card is print('============= Random Agent ============') print_card(env.get_perfect_information()['hand_cards'][1]) print('=============== Result ===============') if payoffs[0] > 0: print('You win {} chips!'.format(payoffs[0])) elif payoffs[0] == 0: print('It is a tie.') else: print('You lose {} chips!'.format(-payoffs[0])) print('') input("Press any key to continue...")
def _print_state(state, action_record): ''' Print out the state Args: state (dict): A dictionary of the raw state action_record (list): A list of the historical actions ''' _action_list = [] for i in range(1, len(action_record)+1): if action_record[-i][0] == state['current_player']: break _action_list.insert(0, action_record[-i]) for pair in _action_list: print('>> Player', pair[0], 'chooses', pair[1]) print('\n=============== Community Card ===============') print_card(state['public_cards']) print('============= Player',state["current_player"],'- Hand =============') print_card(state['hand']) print('=============== Chips ===============') print('In Pot:',state["pot"]) print('Remaining:',state["stakes"]) print('\n=========== Actions You Can Choose ===========') print(', '.join([str(index) + ': ' + str(action) for index, action in enumerate(state['legal_actions'])])) print('') print(state)