How to use the rlcard.games.uno.card.UnoCard 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 / rlcard / games / uno / utils.py View on Github external
def init_deck():
    deck = []
    card_info = Card.info
    for color in card_info['color']:

        # init number cards
        for num in card_info['trait'][:10]:
            deck.append(Card('number', color, num))
            if num != '0':
                deck.append(Card('number', color, num))

        # init action cards
        for action in card_info['trait'][10:13]:
            deck.append(Card('action', color, action))
            deck.append(Card('action', color, action))

        # init wild cards
        for wild in card_info['trait'][-2:]:
            deck.append(Card('wild', color, wild))
    # test
    #for card in deck:
    #    print(card.type, card.color, card.trait)
    #input()
    # #
github datamllab / rlcard / rlcard / games / uno / round.py View on Github external
def flip_top_card(self):
        ''' Flip the top card of the card pile

        Returns:
            (object of UnoCard): the top card in game

        '''
        top = self.dealer.flip_top_card()
        if top.trait == 'wild':
            top.color = np.random.choice(UnoCard.info['color'])
        self.target = top
        self.played_cards.append(top)
        return top
github datamllab / rlcard / rlcard / games / uno / utils.py View on Github external
for color in card_info['color']:

        # init number cards
        for num in card_info['trait'][:10]:
            deck.append(Card('number', color, num))
            if num != '0':
                deck.append(Card('number', color, num))

        # init action cards
        for action in card_info['trait'][10:13]:
            deck.append(Card('action', color, action))
            deck.append(Card('action', color, action))

        # init wild cards
        for wild in card_info['trait'][-2:]:
            deck.append(Card('wild', color, wild))
    # test
    #for card in deck:
    #    print(card.type, card.color, card.trait)
    #input()
    # #

    return deck
github datamllab / rlcard / rlcard / envs / uno.py View on Github external
def print_state(self, player):
        ''' Print out the state of a given player

        Args:
            player (int): Player id
        '''
        state = self.game.get_state(player)
        print('\n=============== Your Hand ===============')
        UnoCard.print_cards(state['hand'])
        print('')
        print('=============== Last Card ===============')
        UnoCard.print_cards(state['target'], wild_color=True)
        print('')
        print('========== Agents Card Number ===========')
        for i in range(self.player_num):
            if i != self.active_player:
                print('Agent {} has {} cards.'.format(i, len(self.game.players[i].hand)))
        print('======== Actions You Can Choose =========')
        for i, action in enumerate(state['legal_actions']):
            print(str(ACTION_SPACE[action])+': ', end='')
            UnoCard.print_cards(action, wild_color=True)
            if i < len(state['legal_actions']) - 1:
                print(', ', end='')
        print('\n')
github datamllab / rlcard / rlcard / envs / uno.py View on Github external
def print_action(action):
        ''' Print out an action in a nice form

        Args:
            action (str): A string a action
        '''
        UnoCard.print_cards(action, wild_color=True)
github datamllab / rlcard / rlcard / games / uno / utils.py View on Github external
def init_deck():
    deck = []
    card_info = Card.info
    for color in card_info['color']:

        # init number cards
        for num in card_info['trait'][:10]:
            deck.append(Card('number', color, num))
            if num != '0':
                deck.append(Card('number', color, num))

        # init action cards
        for action in card_info['trait'][10:13]:
            deck.append(Card('action', color, action))
            deck.append(Card('action', color, action))

        # init wild cards
        for wild in card_info['trait'][-2:]:
            deck.append(Card('wild', color, wild))
    # test
    #for card in deck:
    #    print(card.type, card.color, card.trait)
    #input()
    # #

    return deck
github datamllab / rlcard / rlcard / games / uno / utils.py View on Github external
def init_deck():
    deck = []
    card_info = Card.info
    for color in card_info['color']:

        # init number cards
        for num in card_info['trait'][:10]:
            deck.append(Card('number', color, num))
            if num != '0':
                deck.append(Card('number', color, num))

        # init action cards
        for action in card_info['trait'][10:13]:
            deck.append(Card('action', color, action))
            deck.append(Card('action', color, action))

        # init wild cards
        for wild in card_info['trait'][-2:]:
            deck.append(Card('wild', color, wild))
github datamllab / rlcard / rlcard / games / uno / round.py View on Github external
def _perform_draw_action(self, players):
        # replace deck if there is no card in draw pile
        if not self.dealer.deck:
            self.replace_deck()
            #self.is_over = True
            #self.winner = UnoJudger.judge_winner(players)
            #return None

        card = self.dealer.deck.pop()

        # draw a wild card
        if card.type == 'wild':
            card.color = np.random.choice(UnoCard.info['color'])
            self.target = card
            self.played_cards.append(card)
            self.current_player = (self.current_player + self.direction) % self.num_players

        # draw a card with the same color of target
        elif card.color == self.target.color:
            if card.type == 'number':
                self.target = card
                self.played_cards.append(card)
                self.current_player = (self.current_player + self.direction) % self.num_players
            else:
                self.played_cards.append(card)
                self._preform_non_number_action(players, card)

        # draw a card with the diffrent color of target
        else: