def take_turn(self) -> CardAction:
        last_card_played = self.get_game_helper().get_last_card_played()
        my_hand = self.get_game_helper().get_hand()
        matched_cards_on_color = []
        wild_cards = []
        if last_card_played.card_type not in [CardType.DRAW_TWO, CardType.REVERSE, CardType.SKIP,
                                              CardType.WILD, CardType.WILD_DRAW_FOUR]:
            matched_cards_on_color = [c for c in my_hand if c.color_type == last_card_played.color_type]
        matched_cards_on_value = [c for c in my_hand if c.card_type == last_card_played.card_type]
        matched_cards_on_value_and_color = [c for c in matched_cards_on_value if
                                            c.color_type == last_card_played.color_type]
        if last_card_played.card_type not in [CardType.DRAW_TWO, CardType.WILD_DRAW_FOUR]:
            wild_cards = [c for c in my_hand if c.card_type == CardType.WILD or c.card_type == CardType.WILD_DRAW_FOUR]
        if len(matched_cards_on_color) > 0:
            return CardAction(ActionType.PLAY, random.choice(matched_cards_on_color))
        elif len(wild_cards) > 0:
            random_wild_card = random.choice(wild_cards)
            # Set random color for the wild card
            random_wild_card.color_type = random.choice(
                [ColorType.BLUE, ColorType.GREEN, ColorType.RED, ColorType.YELLOW])
            return CardAction(ActionType.PLAY, random_wild_card)
        elif len(matched_cards_on_value_and_color) > 0:

            return CardAction(ActionType.PLAY, random.choice(matched_cards_on_value_and_color))

        else:
            return CardAction(ActionType.SKIP)
Beispiel #2
0
 def get_turn(self):
     # copied from random
     last_card_played = self.get_game_helper().get_last_card_played()[0]
     my_hand = self.get_game_helper().get_hand()
     matched_cards_on_color = [c for c in my_hand if c.color_type == last_card_played.color_type]
     matched_cards_on_value = [c for c in my_hand if c.card_type == last_card_played.card_type]
     wild_cards = [c for c in my_hand if c.card_type == CardType.WILD or c.card_type == CardType.WILD_DRAW_FOUR]
     if len(matched_cards_on_color) > 0:
         return CardAction(ActionType.PLAY, random.choice(matched_cards_on_color))
     elif len(matched_cards_on_value) > 0:
         return CardAction(ActionType.PLAY, random.choice(matched_cards_on_value))
     elif len(wild_cards) > 0:
         return CardAction(ActionType.PLAY, random.choice(wild_cards))
     else:
         return CardAction(ActionType.SKIP)
Beispiel #3
0
 def take_turn(self) -> CardAction:
     valid_hand = self.get_game_helper().get_valid_hand()
     if len(valid_hand) > 0:
         return CardAction(ActionType.PLAY, valid_hand[0])
     else:
         return CardAction(ActionType.SKIP)
Beispiel #4
0
 def take_turn(self) -> CardAction:
     card = self.get_game_helper().get_hand()[0]
     return CardAction(ActionType.PLAY, card)
Beispiel #5
0
    def take_turn(self) -> CardAction:

        self.top_card_in_pile = self.get_game_helper().get_card_pile()[-1]
        self.card_played = self.get_game_helper().get_last_card_played()
        card = self.get_game_helper().get_hand()[0]
        return CardAction(ActionType.PLAY, card)