How to use the rlcard.utils.utils.get_downstream_player_id function in rlcard

To help you get started, we’ve selected a few rlcard examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datamllab / rlcard / tests / games / test_doudizhu_game.py View on Github external
def test_proceed_game(self):
        game = Game()
        state, player_id = game.init_game()
        while not game.is_over():
            action = np.random.choice(list(state['actions']))
            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
            if not game.is_over():
                self.assertIsNotNone(state['actions'])
        for player_id in range(3):
            state = game.get_state(player_id)
            self.assertIsNone(state['actions'])
github datamllab / rlcard / tests / utils / test_utils.py View on Github external
def test_get_downstream_player_id(self):
        players = init_players(5)
        self.assertEqual(get_downstream_player_id(players[4], players), 0)
github datamllab / rlcard / tests / envs / test_doudizhu_env.py View on Github external
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))
github datamllab / rlcard / rlcard / games / doudizhu / game.py View on Github external
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 = merge(player_up.current_hand, player_down.current_hand, key=functools.cmp_to_key(doudizhu_sort_card))
        return cards2str(others_hand)
github datamllab / rlcard / rlcard / games / doudizhu / game.py View on Github external
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

        return state, next_id