def score(cls, dealer, level, strain, declarer, tries, mode=None): # target = level + 6 dealers = [] declarers = [declarer] * tries strains = [strain] * tries 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:] dealers.append(tmp_dealer) max_tricks = solve_all(dealers, strains, declarers) 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)
def score_all(cls, dealer, declarer, tries, mode=None): dealers = [] declarers = [declarer] * tries strains = [[i] * tries for i in Strain] # cover strains from 0-4 scores_for_all_strains = [0] * 35 # for 35 actions 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:] dealers.append(tmp_dealer) for i, s in enumerate(Strain): # 0-4 max_tricks = solve_all(dealers, strains[i], declarers) for level in range(1, 8): # 1-7 if mode == "IMP": scores = [IMP_TABLE[(level, s, trick)] for trick in max_tricks] else: target = level+6 scores = [t - target for t in max_tricks] idx = convert_level_strain2action(level, s) # find the action idx scores_for_all_strains[idx] = np.mean(scores) return scores_for_all_strains
def dd_all_tricks(self, strain, leader): """Compute declarer's number of double dummy tricks for all leads.""" return dds.solve_all(self, strain, leader)