コード例 #1
0
def _prob_5cards():
    # 发五张牌, 各个牌型的概率
    result = {}
    combines = list(combinations(ALLCARDS, 5))
    for cards in combines:
        hand = Hand.show_hand(cards)
        result.setdefault(hand, 0)
        result[hand] += 1
    result = sorted(result.items(), key=lambda x: x[1], reverse=True)
    for i, item in enumerate(result):
        item = list(item)
        item.append(round(item[1] / len(combines), 10))
        result[i] = tuple(item)
    return result
コード例 #2
0
def _statistic_5cards(hand_count):
    # 随机发五张牌,统计n手牌的牌型分布
    result = {}
    for i in range(hand_count):
        cards = Dealer.deal_5cards(1)[0]
        # pile = copy(ALLCARDS)
        # shuffle(pile)
        # cards = sample(pile, 5)
        hand = Hand.show_hand(cards)
        result.setdefault(hand, 0)
        result[hand] += 1
    result = sorted(list(result.items()), key=lambda x: x[1], reverse=True)
    for i, item in enumerate(result):
        item = list(item)
        item.append(round(item[1] / hand_count, 10))
        result[i] = tuple(item)
    return result
コード例 #3
0
def _statistic_7cards(hand_count):
    # 随机发7张牌,统计n手牌的牌型分布
    result = {}
    for i in range(hand_count):
        pile = copy(ALLCARDS)
        shuffle(pile)
        cards = sample(pile, 7)
        best_hand = select_best_hand(cards[:2], cards[2:])
        hand = Hand.show_hand(best_hand)
        result.setdefault(hand, 0)
        result[hand] += 1
    result = sorted(result.items(), key=lambda x: x[1], reverse=True)
    for i, item in enumerate(result):
        item = list(item)
        item.append(round(item[1] / hand_count, 10))
        result[i] = tuple(item)
    return result
コード例 #4
0
def _statistic_games(players=2, games=10000):
    # 统计若干玩家若干对局之后,获胜者的牌型分布
    result = {}
    for i in range(games):
        dealer = Dealer(players)
        player_cards = dealer.deal_hand()
        public_cards = dealer.deal_public()
        winner_id = winner(player_cards, public_cards)
        winner_hand = select_best_hand(player_cards[winner_id[0]],
                                       public_cards)
        hand = Hand.show_hand(winner_hand)
        result.setdefault(hand, 0)
        result[hand] += 1
    result = sorted(result.items(), key=lambda x: x[1], reverse=True)
    for i, item in enumerate(result):
        item = list(item)
        item.append(round(item[1] / games, 10))
        result[i] = tuple(item)
    return result