Example #1
0
    def get_best_play(self, game_state):
        """
        Returns lowest play of play_type
        """
        prev_play = game_state.prev_play
        unrevealed_cards = []
        if not prev_play or prev_play.position == self.position:
            # lead play
            next_play = self.get_best_lead_play(game_state)
        else:
            prev_type = prev_play.play_type
            if prev_type == DOUBLE_JOKER:
                return Play.get_pass_play(position=self.position)
            elif prev_type == SINGLES:
                next_play = self.get_best_singles(game_state)
            elif prev_type == DOUBLES:
                next_play = self.get_best_doubles(game_state)
            elif prev_type == TRIPLES:
                next_play = self.get_best_triples(game_state)
            elif prev_type == STRAIGHTS:
                next_play = self.get_best_straights(game_state)
            elif prev_type == DOUBLE_STRAIGHTS:
                next_play = self.get_best_double_straights(game_state)
            elif prev_type == ADJ_TRIPLES:
                next_play = self.get_best_adj_triples(game_state)
            elif prev_type == QUADRUPLES:
                next_play = self.get_best_quad(game_state)
            # if next play is none and the player has less than 5 * (number of wilds in hand) cards,
            # play wilds
            # and game_state.get_player_num_cards(prev_play.position) <= 5 * self.hand.get_num_wild():

        if next_play:
            next_play.position = self.position
        return next_play
Example #2
0
 def get_low_wild(self, other_card):
     """
     Returns the lowest wild play that is above given card
     Pos of the play is -1
     """
     iterator = self.generate_possible_wilds(other_card)
     return next(iterator, Play.get_pass_play())
Example #3
0
def get_play_from_input(user_input):
    """returns card play based on user's input"""
    if not user_input:
        return Play.get_pass_play()
    player_card_strs = user_input.split()
    played_cards = Card.strs_to_cards(player_card_strs)
    return Play.get_play_from_cards(played_cards)
Example #4
0
 def get_best_adj_triples(self, game_state):
     best_play = self._get_best_singular_straight(game_state, 3)
     if not best_play:
         return Play.get_pass_play(position=self.position)
     extra_each_count = game_state.prev_play.num_extra // 2
     return self._get_best_play_with_extra(game_state, best_play, 2,
                                           extra_each_count)
Example #5
0
def _get_single_best_play(card_plays, player, game_state):
    """Gets the best play optimized for returning only one play"""
    best_play = Play.get_pass_play(position=player.position)
    for play in card_plays:
        play.position = player.position
        play.strength = estimate_play_strength(play, player, game_state)
        if not best_play or play.strength > best_play.strength:
            best_play = play
    return best_play
Example #6
0
 def get_low_adj_triple(self, other_card, num_extra):
     """
     Gets the lowest adj triple that meets the properties
     Arguments:
     other_card -- the lowest card value of the triples
     num_extra -- 2 if it carries 2 singles
                    4 if it carries 2 doubles
     Returns play with pos of -1 or None
     """
     iterator = self.generate_possible_adj_triples(other_card, num_extra)
     return next(iterator, Play.get_pass_play())
Example #7
0
 def get_low(self, other_card, each_count, extra=0):
     """
     Gets the lowest basic that meets the properties
     Arguments:
     other_card -- lowest card in the basic
     each_count -- if its a single, double, triple, or quad (wild)
     extra -- the number of extra cards (1 or 2 for triple)
                                        (2 or 4 for quad)
     Returns the lowest play with pos -1 or None
     """
     iterator = self.generate_possible_basics(other_card, each_count, extra=extra)
     return next(iterator, Play.get_pass_play())
Example #8
0
        def wrapper(self, game_state):
            best_play = get_best_specific_play(self, game_state)
            if best_play:
                pass_play_strength = estimate_play_strength(
                    None, self, game_state)

                if best_play.strength < pass_play_strength - self.pass_play_significance:
                    pass_play = Play.get_pass_play(position=self.position)
                    pass_play.strength = pass_play_strength
                    return pass_play

            return best_play
Example #9
0
    def get_low_straight(self, other_card, each_count, length):
        """
        Gets the lowest straight that meets the properties
        Arguments:
        other_card -- lowest card in the opposing straight
        each_count -- if its a single, double, or triple straight
        length -- length of the opposing straight
                  each_count * distinct number of cards
                  length is ignored when other_card is None

        Returns play with pos of -1 or None
        """
        iterator = self.generate_possible_straights(other_card, each_count, length)
        return next(iterator, Play.get_pass_play())