Esempio n. 1
0
    def play_card(self, rnd: PlayerRound) -> int:
        """
        Player returns a card to play based on the given round information.

        Args:
            rnd: current round

        Returns:
            card to play, int encoded
        """
        # play random

        # get the valid cards to play
        valid_cards = rnd.get_valid_cards()

        # select a random card
        return np.random.choice(np.flatnonzero(valid_cards))
Esempio n. 2
0
def calculate_lowest_card_per_color(rnd: PlayerRound) -> np.array:
    lowest_card_per_color = np.array([-1, -1, -1, -1])

    for c in range(0, 4):
        cards = rnd.get_valid_cards()[c * 9:(c * 9) + 9]

        if c == rnd.trump:
            #check lowest trump
            lowest_card_per_color[c] = get_lowest_trump(c, cards)
        elif rnd.trump == 5:
            #check lowest unde
            lowest_card_per_color[c] = get_lowest_unde(c, cards)
        else:
            #check lowest obe
            lowest_card_per_color[c] = get_lowest_obe(c, cards)

    return lowest_card_per_color
Esempio n. 3
0
    def play_card(self, rnd: PlayerRound) -> int:
        """
        Implement the action to play hearts.
        Args:
            rnd: The round for which to play
        Returns:
            the card to play, must be a valid card
        """
        # we can check if we are playing the correct game
        assert rnd.jass_type == JASS_HEARTS

        # get the valid cards to play
        valid_cards = rnd.get_valid_cards()

        # lets divide our cards into heart and other cards
        my_heart_cards = valid_cards * color_masks[HEARTS, :]
        my_other_cards = valid_cards - my_heart_cards

        if rnd.nr_cards_in_trick == 0:
            # we are the first player, so we can select what to play
            # lets select some random non-heart card if we have any (not that this is necessarily
            # a good strategy :-)
            if my_other_cards.sum() > 0:
                card = np.random.choice(np.flatnonzero(my_other_cards))
            else:
                # just play a random valid card
                card = np.random.choice(np.flatnonzero(valid_cards))
        else:
            # if we have to give a card, lets try to give a heart card
            if my_heart_cards.sum() > 0:
                card = np.random.choice(np.flatnonzero(my_heart_cards))
            else:
                # just play a random valid card
                card = np.random.choice(np.flatnonzero(valid_cards))

        self._logger.debug('Played card: {}'.format(card_strings[card]))
        return card
Esempio n. 4
0
 def _check_more_than_one_valid_card(self, rnd: PlayerRound) -> bool:
     return rnd.get_valid_cards().sum() > 1
Esempio n. 5
0
 def play_card(self, rnd: PlayerRound) -> int:
     valid_cards = rnd.get_valid_cards()
     card = np.random.choice(np.flatnonzero(valid_cards))
     self._logger.debug('Played card: {}'.format(card_strings[card]))
     return card
Esempio n. 6
0
def calculate_score(rnd: PlayerRound, trumpToCheck=None) -> np.array:
    """trump can be given to check specific trump on a round otherwise the rnd trump is taken
        return an array with four elemnts which each containing the score of one color """
    trump = None
    if trumpToCheck is not None:
        trump = trumpToCheck
    else:
        trump = rnd.trump

    score_per_color = np.array([0, 0, 0, 0])

    if trump == 0:
        #it's a D: Schellen trump
        score_per_color[0] = get_score_per_color_and_trump(
            0, rnd.get_valid_cards(), trump, 0)
        score_per_color[1] = get_score_per_color_and_trump(
            1, rnd.get_valid_cards(), trump, 1)
        score_per_color[2] = get_score_per_color_and_trump(
            2, rnd.get_valid_cards(), trump, 1)
        score_per_color[3] = get_score_per_color_and_trump(
            3, rnd.get_valid_cards(), trump, 1)

    elif trump == 1:
        #it's a H: Rosen trump
        score_per_color[0] = get_score_per_color_and_trump(
            0, rnd.get_valid_cards(), trump, 1)
        score_per_color[1] = get_score_per_color_and_trump(
            1, rnd.get_valid_cards(), trump, 0)
        score_per_color[2] = get_score_per_color_and_trump(
            2, rnd.get_valid_cards(), trump, 1)
        score_per_color[3] = get_score_per_color_and_trump(
            3, rnd.get_valid_cards(), trump, 1)

    elif trump == 2:
        #it's a S: Schilten trump
        score_per_color[0] = get_score_per_color_and_trump(
            0, rnd.get_valid_cards(), trump, 1)
        score_per_color[1] = get_score_per_color_and_trump(
            1, rnd.get_valid_cards(), trump, 1)
        score_per_color[2] = get_score_per_color_and_trump(
            2, rnd.get_valid_cards(), trump, 0)
        score_per_color[3] = get_score_per_color_and_trump(
            3, rnd.get_valid_cards(), trump, 1)

    elif trump == 3:
        #it's a C: Eichel trump
        score_per_color[0] = get_score_per_color_and_trump(
            0, rnd.get_valid_cards(), trump, 1)
        score_per_color[1] = get_score_per_color_and_trump(
            1, rnd.get_valid_cards(), trump, 1)
        score_per_color[2] = get_score_per_color_and_trump(
            2, rnd.get_valid_cards(), trump, 1)
        score_per_color[3] = get_score_per_color_and_trump(
            3, rnd.get_valid_cards(), trump, 0)

    elif trump == 4:
        #it's O: Obe
        #score_per_color[0] = get_score_per_color_and_trump(0, rnd.get_valid_cards(), trump, 1)
        #score_per_color[1] = get_score_per_color_and_trump(1, rnd.get_valid_cards(), trump, 1)
        #score_per_color[2] = get_score_per_color_and_trump(2, rnd.get_valid_cards(), trump, 1)
        #score_per_color[3] = get_score_per_color_and_trump(3, rnd.get_valid_cards(), trump, 1)
        pass

    elif trump == 5:
        #it's U: Une-Ufe
        #score_per_color[0] = get_score_per_color_and_trump(0, rnd.get_valid_cards(), trump, 2)
        #score_per_color[1] = get_score_per_color_and_trump(1, rnd.get_valid_cards(), trump, 2)
        #score_per_color[2] = get_score_per_color_and_trump(2, rnd.get_valid_cards(), trump, 2)
        #score_per_color[3] = get_score_per_color_and_trump(3, rnd.get_valid_cards(), trump, 2)
        pass

    else:
        raise ValueError(
            "Wrong trump number! only works for 0 to 5 (D, H, S, C, Obe, Unde)"
        )

    print("Calculate Score - Trump: {}, ScorePerColor: {}".format(
        trump_strings_german_long[trump], score_per_color))
    return score_per_color