コード例 #1
0
def update_state_deck_draw(state, new_card, player, p1_obs, p2_obs):

    old_state = 10

    if (player == 1):

        new_state = 0
        update_p1 = True

    elif (player == 2):

        new_state = 3
        update_p1 = False

    old_idx = get_idx(new_card, old_state)
    new_idx = get_idx(new_card, new_state)

    state[old_idx] = 0
    state[new_idx] = 1

    if update_p1:

        p1_obs[old_idx] = 0
        p1_obs[new_idx] = 1

    else:

        p2_obs[old_idx] = 0
        p2_obs[new_idx] = 1
コード例 #2
0
    def initialize_state(self):

        state_vec = np.zeros(572, dtype=np.int8)

        for deck_card in self.gameboard.deck.deckofcards:

            state = 10

            idx = get_idx(deck_card, state)
            state_vec[idx] = 1

        for p1_hand_card in self.gameboard.p1_board.hand:

            state = 0

            idx = get_idx(p1_hand_card, state)
            state_vec[idx] = 1

        for p2_hand_card in self.gameboard.p2_board.hand:

            state = 3

            idx = get_idx(p2_hand_card, state)
            state_vec[idx] = 1

        return state_vec
コード例 #3
0
def update_state_discard(state, discard_card, top_discard, player, p1_obs,
                         p2_obs):

    suit = int(discard_card / 13)
    top_discarded_card = top_discard[suit]

    # Check if there is currently a top discarded card
    if (top_discarded_card != -1):

        # Check if player 1 has the current top discarded card and update accordingly
        if (state[get_idx(top_discarded_card, 7)] == 1):

            new_discarded_card_state = 6

        elif (state[get_idx(top_discarded_card, 9)] == 1):

            new_discarded_card_state = 8

        else:

            print('Error')
            for state_opt in range(11):
                print(state[get_idx(top_discarded_card, state_opt)])

        new_idx = get_idx(top_discarded_card, new_discarded_card_state)

        zero_card(state, top_discarded_card)
        zero_card(p1_obs, top_discarded_card)
        zero_card(p2_obs, top_discarded_card)

        state[new_idx] = 1
        p1_obs[new_idx] = 1
        p2_obs[new_idx] = 1

    # Change the discarded card to the top of its respective suit
    if (player == 1):

        new_state = 7

    elif (player == 2):

        new_state = 9

    new_idx = get_idx(discard_card, new_state)

    zero_card(state, discard_card)
    zero_card(p1_obs, discard_card)
    zero_card(p2_obs, discard_card)

    state[new_idx] = 1
    p1_obs[new_idx] = 1
    p2_obs[new_idx] = 1

    # Update the list of top discarded cards
    top_discard[suit] = discard_card
コード例 #4
0
    def get_observation(self, player):
        '''Denote all cards in the opposing player's hand as well as the deck with state 10.'''

        if (player == 1):
            opp_hand = self.gameboard.p2_board.hand
            state_to_hide = 3

        elif (player == 2):
            opp_hand = self.gameboard.p1_board.hand
            state_to_hide = 0

        obs = self.state.copy()
        hidden_state = 10

        for card in opp_hand:

            hide_idx = get_idx(card, state_to_hide)
            new_idx = get_idx(card, hidden_state)

            obs[hide_idx] = 0
            obs[new_idx] = 1

        return obs
コード例 #5
0
def update_state_discard_draw_new_top_card(state, new_top_card, player, p1_obs,
                                           p2_obs):

    if (new_top_card is None):
        return

    # Check if player 1 has the current top discarded card and update accordingly
    if (state[get_idx(new_top_card, 6)] == 1):

        new_state = 7

    elif (state[get_idx(new_top_card, 8)] == 1):

        new_state = 9

    new_idx = get_idx(new_top_card, new_state)

    zero_card(state, new_top_card)
    zero_card(p1_obs, new_top_card)
    zero_card(p2_obs, new_top_card)

    state[new_idx] = 1
    p1_obs[new_idx] = 1
    p2_obs[new_idx] = 1
コード例 #6
0
def update_state_discard_draw_new_card(state, new_card, player, p1_obs,
                                       p2_obs):

    zero_card(state, new_card)
    zero_card(p1_obs, new_card)
    zero_card(p2_obs, new_card)

    if (player == 1):

        new_state = 0

    elif (player == 2):

        new_state = 3

    new_idx = get_idx(new_card, new_state)

    state[new_idx] = 1
    p1_obs[new_idx] = 1
    p2_obs[new_idx] = 1
コード例 #7
0
def update_state_play(state, play_card, flex_options, player, player_board,
                      p1_obs, p2_obs):
    '''Update both the state and the flex_options list after a new card is played. At this point
    the hand has been updated but these variables have not, so flex options contains information 
    about flex options before current card played. 'Flex option' elements are:

    -1: suit initialized
    0: no current flex play
    1: flex play for given suit 
    '''

    suit = int(play_card / 13)

    # If the suit was previously initialized, the flex options cannot change
    if (flex_options[suit] == -1):

        # Designate card as flex option in state
        if (player == 1):
            new_state = 1

        elif (player == 2):
            new_state = 4

    played_cards = player_board.query_played_cards(suit)
    flex_option = ace_degenerate_scoring(suit, played_cards)

    # If there was not a previous flex option, we only need to change the state of the new card
    if (flex_options[suit] == 0):

        # If there is a flex option with the addition of the new card, the new card must be the flex
        # option
        if flex_option:

            # Update flex options
            flex_options[suit] = 1

            # Designate card as flex option in state
            if (player == 1):
                new_state = 2

            elif (player == 2):
                new_state = 5

        # If there still isn't a flex option, the new card is simply on the board
        else:

            if (player == 1):
                new_state = 1

            elif (player == 2):
                new_state = 4

    # If there was previously a flex option and a new card is played, we no longer have a flex option
    elif (flex_options[suit] == 1):

        flex_options[suit] == -1

        ace = 13 * suit

        # The previous ace that gave the flex option is now a standard board play.
        # The new card is necessarily a standard board play as well.
        if (player == 1):

            old_ace_state = 2
            new_state = 1

        elif (player == 2):

            old_ace_state = 5
            new_state = 4

        old_ace_idx = get_idx(ace, old_ace_state)

        state[old_ace_idx] = 0
        p1_obs[old_ace_idx] = 0
        p2_obs[old_ace_idx] = 0

    new_idx = get_idx(play_card, new_state)

    zero_card(state, play_card)
    zero_card(p1_obs, play_card)
    zero_card(p2_obs, play_card)

    state[new_idx] = 1
    p1_obs[new_idx] = 1
    p2_obs[new_idx] = 1
コード例 #8
0
def zero_card(arr, card):
    '''Remove any state information about a given card.'''

    for state_opt in range(11):
        arr[get_idx(card, state_opt)] = 0