Exemplo n.º 1
0
        def check_card_potential(card,
                                 player,
                                 board_state,
                                 current_rank=None,
                                 pure_info=False):
            player_distance = player - original_player_number - 1
            if player_distance < 0:
                player_distance += round_info.number_of_players

            already_hinted = False
            if card.revealed_suit is None and card.revealed_rank is None:
                for players in hinted_plays:
                    if hinted_plays[players][card.real_suit][
                            card.real_rank] != 0:
                        already_hinted = True

            card_potential = pow(distance_to_player_multiplier, player_distance) *\
                             pow(lower_rank_multiplier, 5 - card.real_rank.value)

            if (card.revealed_suit is not None or card.revealed_rank is not None) and \
                    card.real_rank.value - board_state[card.real_suit] <= 1 and \
                    self.card_hint_type[player][card.hand_position] == "Play":
                card_potential *= double_hint_multiplier

            if card.real_rank.value <= 4 and card.real_rank.value - board_state[card.real_suit] == 1 and \
                    known[card.real_suit][utils.Rank(card.real_rank.value + 1)] > 0:
                card_potential *= chain_bonus_multiplier

            if already_hinted:
                card_potential += false_tip_penalty

            if pure_info \
                    or (max(round_info.board_state.values()) < card.real_rank.value - 1 and current_rank is None) \
                    or (self.card_hint_type[player][card.hand_position] == "Information"):

                card_potential = information_tip_value * pow(distance_to_player_multiplier, player_distance) * \
                                 pow(lower_rank_multiplier, card.real_rank.value - 1)

                if not already_hinted and \
                        card.real_rank.value - board_state[card.real_suit] == 1 and \
                        self.card_hint_type[player][card.hand_position] == "Information":
                    card_potential = pow(distance_to_player_multiplier, player_distance) * \
                                     pow(lower_rank_multiplier, 5 - card.real_rank.value)

                if card.real_rank.value <= 4 and card.real_rank.value - board_state[card.real_suit] == 1 and \
                        known[card.real_suit][utils.Rank(card.real_rank.value + 1)] > 0:
                    card_potential *= chain_bonus_multiplier

            elif (card.revealed_suit is None and card.revealed_rank is None) and \
                    ((current_rank is None and board_state[card.real_suit] is not card.real_rank.value - 1) or
                     (current_rank is not None and card.real_rank.value is not current_rank)):
                card_potential += false_tip_penalty

            if current_rank is not None and card.real_rank.value is current_rank:
                current_rank += 1

            return card_potential, current_rank
Exemplo n.º 2
0
    def check_for_play(self, round_info, player_number):
        if player_number is round_info.player_turn:
            player_hand = round_info.true_hand_info()
        else:
            player_hand = utils.get_player_hand_by_number(
                round_info, player_number)

        known = self.list_all_known_cards(round_info, player_number)

        best_card = -1
        chain_bonus = False
        best_card_rank = 6
        for card in player_hand:
            if round_info.board_state[
                    card.real_suit] + 1 is card.real_rank.value:
                new_chain = False
                if card.real_rank.value <= 4 and known[card.real_suit][
                        utils.Rank(card.real_rank.value + 1)] > 0:
                    new_chain = True
                if (chain_bonus and new_chain and card.real_rank.value < best_card_rank) or \
                        (not chain_bonus and (new_chain or card.real_rank.value < best_card_rank)):
                    best_card = card.hand_position
                    best_card_rank = card.real_rank.value
                    chain_bonus = new_chain

        if best_card >= 0:
            return ChoiceDetails(Choice.PLAY, best_card)
        return False
                def basic_check(targets, hint, rank=False):
                    current_alignment = 0
                    future_alignment = 0
                    corrected = 0
                    obviously_useless = 0
                    falsely_hinted = 0
                    chain_bonus = 0
                    card_age = 0
                    oldest_card = False
                    last_remaining = 0

                    for card in targets:
                        already_hinted = False
                        if card.revealed_suit is None and card.revealed_rank is None:
                            for players in hinted_plays:
                                if players is not player_number and \
                                        hinted_plays[players][card.real_suit][card.real_rank] != 0:
                                    already_hinted = True

                        card_with_hint = deepcopy(card)
                        if rank:
                            card_with_hint.revealed_rank = hint
                        else:
                            card_with_hint.revealed_suit = hint

                        if self.check_card_usefulness(round_info, card_with_hint) is not False \
                                and self.check_card_usefulness(round_info, card) is False:
                            obviously_useless += 1

                        if rank:
                            card_with_hint.revealed_suit = card.real_suit
                        else:
                            card_with_hint.revealed_rank = card.real_rank

                        if round_info.board_state[card.real_suit] is card.real_rank.value - 1:
                            if self.remaining[card.real_suit][card.real_rank] == 1 \
                                    and ((rank and card.revealed_suit is None)
                                         or (not rank and card.revealed_rank is None)):
                                last_remaining += 1

                            if card.revealed_rank is not None or card.revealed_suit is not None and \
                                    round_info.current_turn - card.drawn_on_turn > 2:
                                corrected += 1

                            if already_hinted:
                                falsely_hinted += 1

                            else:
                                current_alignment += 1
                                chain = 1
                                if card.real_rank.value + chain <= 5 and \
                                        self.known[card.real_suit][utils.Rank(card.real_rank.value + chain)] > 0:
                                    chain += 1
                                    chain_bonus += 1

                        elif self.check_card_usefulness(round_info, card_with_hint) is False:
                            if self.remaining[card.real_suit][card.real_rank] == 1 \
                                    and ((rank and card.revealed_suit is None)
                                         or (not rank and card.revealed_rank is None)):
                                last_remaining += 1

                            if card.revealed_rank is not None or card.revealed_suit is not None:
                                corrected += 1

                            future_alignment += 1

                        if round_info.board_state[card.real_suit] is not card.real_rank.value - 1 \
                                and ((rank and card.revealed_suit is None)
                                     or (not rank and card.revealed_rank is None)):
                            falsely_hinted += 1

                        if round_info.current_turn - card.drawn_on_turn > card_age:
                            card_age = round_info.current_turn - card.drawn_on_turn

                        if card.hand_position is self.oldest_card[card.player_number]:
                            oldest_card = True

                    if card_age > 3:
                        card_age = 3

                    if current_alignment > 2:
                        current_alignment = 2

                    if future_alignment > 2:
                        future_alignment = 2

                    if obviously_useless > 2:
                        obviously_useless = 2

                    if corrected > 2:
                        corrected = 2

                    if falsely_hinted > 2:
                        falsely_hinted = 2

                    chain_bonus = math.ceil(chain_bonus / 2)
                    if chain_bonus > 2:
                        chain_bonus = 2

                    if last_remaining > 1:
                        last_remaining = 1

                    state = (rank, current_alignment, future_alignment, obviously_useless, corrected, falsely_hinted,
                             chain_bonus, last_remaining, card_age, oldest_card, player_distance)

                    weights = self.get_hint_weights(state)
                    return state, weights, player_number, hint
Exemplo n.º 4
0
    def check_for_hinted_play(self, round_info, player_number):
        if player_number is round_info.player_turn:
            player_hand = round_info.player_hand
        else:
            player_hand = utils.get_player_hand_by_number(round_info, player_number)

        alignment_delta = 2
        max_hint_size = 10

        if round_info.lives == 1:
            alignment_delta = 0
            max_hint_size = 1

        hinted_ranks = {}
        hinted_suits = {}
        for suit in utils.Suit:
            hinted_suits[suit] = 0
        for rank in utils.Rank:
            hinted_ranks[rank] = 0

        for x in range(0, len(player_hand)):
            if player_hand[x].revealed_suit is not None and player_hand[x].revealed_rank is None and \
                    self.card_hint_type[player_number][x] == "Play":
                hinted_suits[player_hand[x].revealed_suit] += 1
            if player_hand[x].revealed_rank is not None and player_hand[x].revealed_suit is None and \
                    self.card_hint_type[player_number][x] == "Play":
                hinted_ranks[player_hand[x].revealed_rank] += 1

        known = utils.list_all_known_cards(round_info, player_number)[0]
        remaining = utils.list_remaining_playable_cards(round_info)
        discarded = utils.list_discarded_cards(round_info)

        best_hint = -1
        best_hint_size = max_hint_size
        best_alignment = 0
        hint_type = None

        for suit in hinted_suits:
            if 0 < hinted_suits[suit] <= best_hint_size:
                rank = round_info.board_state[suit] + 1
                if rank <= 5:
                    rank_rank = utils.Rank(rank)
                    if remaining[suit][rank_rank] - known[suit][rank_rank] + discarded[suit][rank_rank] > 0:
                        best_hint = suit
                        best_hint_size = hinted_suits[suit]
                        best_alignment = 1
                        hint_type = 'suit'

        board_alignment = {}
        for rank in utils.Rank:
            board_alignment[rank] = 0
        for suit in round_info.board_state:
            rank = round_info.board_state[suit] + 1
            if rank <= 5:
                rank_rank = utils.Rank(rank)
                if remaining[suit][rank_rank] - known[suit][rank_rank] + discarded[suit][rank_rank] > 0:
                    board_alignment[rank_rank] += 1

        for rank in hinted_ranks:
            if 0 < board_alignment[rank] and ((0 < hinted_ranks[rank] < best_hint_size) or
                                              (0 < hinted_ranks[rank] <= best_hint_size and best_alignment <
                                               board_alignment[rank])):
                best_hint = rank
                best_hint_size = hinted_ranks[rank]
                best_alignment = board_alignment[rank]
                hint_type = 'rank'

        if best_hint != -1 and best_hint_size <= best_alignment + alignment_delta:
            for x in range(0, len(player_hand)):
                if hint_type == 'rank':
                    if player_hand[x].revealed_rank is not None and player_hand[x].revealed_suit is None and \
                            player_hand[x].revealed_rank is best_hint and \
                            self.card_hint_type[player_number][x] == "Play":
                        return ChoiceDetails(
                            Choice.PLAY,
                            x
                        )
                else:
                    if player_hand[x].revealed_suit is not None and player_hand[x].revealed_rank is None and \
                            player_hand[x].revealed_suit is best_hint and \
                            self.card_hint_type[player_number][x] == "Play":
                        return ChoiceDetails(
                            Choice.PLAY,
                            x
                        )

        return False