def test_step(self): env = rlcard.make('doudizhu') _, player_id = env.init_game() player = env.game.players[player_id] _, next_player_id = env.step(env.action_num - 1) self.assertEqual(next_player_id, get_downstream_player_id(player, env.game.players))
def test_step(self): env = Env() _, player_id = env.init_game() player = env.game.players[player_id] _, next_player_id = env.step(308) self.assertEqual(next_player_id, get_downstream_player_id(player, env.game.players))
def step(self, action): ''' Perform one draw of the game Args: action (str): specific action of doudizhu. Eg: '33344' Returns: dict: next player's state int: next player's id ''' if self.allow_step_back: # TODO: don't record game.round, game.players, game.judger if allow_step_back not set pass # perfrom action player = self.players[self.round.current_player] self.round.proceed_round(player, action) if (action != 'pass'): self.judger.calc_playable_cards(player) if self.judger.judge_game(self.players, self.round.current_player): self.winner_id = self.round.current_player next_id = get_downstream_player_id(player, self.players) self.round.current_player = next_id # get next state state = self.get_state(next_id) self.state = state #print("doudizhu状态:",state) return state, next_id
def step(self, action): ''' Perform one draw of the game Args: action (str): specific action of doudizhu. Eg: '33344' Returns: dict: next player's state int: next player's id ''' if self.allow_step_back: # record game history self._record_history() # perfrom action player = self.players[self.round.current_player] self.round.proceed_round(player, action) if self.judger.judge_game(self.players, self.round.current_player): self.winner_id = self.round.current_player next_id = get_downstream_player_id(player, self.players) self.round.current_player = next_id # get next state state = self.get_state(next_id) self.state = state return state, next_id
def _get_others_current_hand(self, player): player_up = self.players[get_upstream_player_id(player, self.players)] player_down = self.players[get_downstream_player_id( player, self.players)] others_hand = (player_up.current_hand + player_down.current_hand) others_hand.sort(key=functools.cmp_to_key(doudizhu_sort_card)) return cards2str(others_hand)
def step(self, action): ''' Perform one draw of the game Args: action (str): specific action of doudizhu. Eg: '33344' Returns: dict: next player's state int: next player's id ''' # record game history player = self.players[self.current_player] self._record_history() self.trace.append((self.current_player, action)) # update cards played if action != 'pass': self._add_played_cards(action) self.state['played_cards'] = self.played_cards # perform action greater_player = self.rounder.proceed_round(player, action) next_player_id = get_downstream_player_id(player, self.players) # update next_state self.state['self'] = next_player_id next_player = self.players[next_player_id] self.state['hand'] = cards2str(next_player.hand) self.state['current_hand'] = cards2str(next_player.current_hand) actions = next_player.available_actions(greater_player, self.judger) self.state['actions'] = actions self.state['others_hand'] = self._get_others_current_hand(next_player) self.current_player = next_player_id return copy.deepcopy(self.state), next_player_id
def test_step(self): env = rlcard.make('simple-doudizhu') _, player_id = env.reset() player = env.game.players[player_id] _, next_player_id = env.step(130) self.assertEqual(next_player_id, get_downstream_player_id(player, env.game.players))
def test_proceed_game(self): game = Game() state, player_id = game.init_game() while not game.is_over(): action = state['actions'][0] state, next_player_id = game.step(action) player = game.players[player_id] self.assertEqual(get_downstream_player_id(player, game.players), next_player_id) player_id = next_player_id for player_id in range(3): state = game.get_state(player_id) self.assertIsNone(state['actions'])
def test_get_downstream_player_id(self): players = init_players(5) self.assertEqual(get_downstream_player_id(players[4], players), 0)