示例#1
0
 def dd_tricks(self, contract_declarer):
     """Compute declarer's number of double-dummy tricks in a contract."""
     strain = Contract.from_str(contract_declarer[:-1]).strain
     declarer = contract_declarer[-1]
     if (strain, declarer) not in self._dd_cache:
         self._dd_cache[strain, declarer] = \
             dds.solve(self, strain, declarer)
     return self._dd_cache[strain, declarer]
示例#2
0
    def score_st(cls, dealer, level, strain, declarer, tries, mode=None):
        max_tricks = []
        # target = level + 6

        for _ in range(tries):
            tmp_dealer = deepcopy(dealer)
            cards = dealer["_remaining"]
            random.shuffle(cards)
            for seat in Seat:
                to_deal = len(Rank) - len(tmp_dealer[seat])
                tmp_dealer[seat] += cards[:to_deal]
                cards = cards[to_deal:]
            max_tricks.append(solve(tmp_dealer, strain, declarer))
            # score = max_trick - target
        if mode == "IMP":
            scores = [IMP_TABLE[(level, strain, trick)] for trick in max_tricks]
            print("IMP mode....")
        else:
            target = level + 6
            scores = [t - target for t in max_tricks]
        return np.mean(scores)
示例#3
0
    def score_all_st(cls, dealer, declarer, tries, mode=None):
        scores_for_all_strains = np.zeros((35, tries))
        idx_table = [[convert_level_strain2action(l, s) for l in range(1, 8)] for s in Strain]

        for t in range(tries):
            tmp_dealer = deepcopy(dealer)
            cards = dealer["_remaining"]
            random.shuffle(cards)
            for seat in Seat:
                to_deal = len(Rank) - len(tmp_dealer[seat])
                tmp_dealer[seat] += cards[:to_deal]
                cards = cards[to_deal:]
            for s in Strain:
                max_trick = solve(tmp_dealer, s ,declarer)
                for level in range(1, 8):
                    idx = idx_table[s][level-1]
                    if mode == "IMP":
                        score = IMP_TABLE[(level, s, max_trick)]
                    else:
                        score = max_trick - level - 6
                    scores_for_all_strains[idx][t] = score
        scores_for_all_strains = np.mean(scores_for_all_strains, axis=-1)
        return scores_for_all_strains