交易七张扑克手时,计算单对概率的异常概率结果



背景:今天,我想我会开始一个小型项目建设模拟器。我设定的第一个任务是交易卡片甲板,检查各种数值生成的概率反对公认的值。我检查的第一个概率是单对概率 - 即(数值(生成被给出的概率是输入数字纸牌交易和双手交易的数量是从单独的洗牌甲板上进行的。卡是从甲板的顶部。在下面,我显示了该程序的开始。我首先测试了数值生成的单对概率对于五张卡。计算值是在内部被接受的单对概率的十分之一对于五张手(但总是高约百分之十的高(:

但是,当我测试数值生成的单对概率时对于七张牌,我发现我从接受的值(例如,典型的计算值= 0.47828;以上= 0.438的接受值(。我运行了最多十个数值实验百万的手交易。计算的单对概率为七个卡手稳定,从公认的值中降低了4%至5%。还不清楚为什么是这种情况。

问题:为什么会这样?我怀疑我的代码没有服用考虑到一些东西,但我无法检测到什么。Python代码如下。。。

注意:问题31381901与此相似。但是在下面的代码中,双重计数问题是通过将Dealt Hand转换为集合的,这将消除重复值,从而将集合的大小(在7张卡手的情况下(从7降低到6。还原表示一对。如果存在三个范围,则该集合的大小为5,因为设置转换将消除三张中的三张卡中的两张。

from random import shuffle
def make_deck():
    '''Make a 52 card deck of cards.  First symbol
    is the value, second symbol is the suit.  Concatenate
    both symbols together.
    Input:  None
    Output:  List
    '''
    value = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
    suit = ['C','H','S','D']
    deck = [j+i for j in value for i in suit]
    return deck

def shuffle_deck(deck, times_to_shuffle=7):
    '''Shuffle a deck of cards produced by make_deck().
    Default:  7 times.
    Input:  list, int
    Output:  list (modified in-place)
    '''
    for n in range(times_to_shuffle):
        shuffle(deck)

def test_for_single_pair(hand, cards_per_hand):
    '''Tests for presence of a single pair in 
    a dealt hand by converting the hand to a set.
    The set representation of a hand with a single
    pair will have one less member than the original
    hand.
    Input: list, int
    Output:  int
    '''
    hand_values_lst = [card[0] for card in hand]
    hand_values_set = set(hand_values_lst)
    set_size = len(hand_values_set)
    if set_size == (cards_per_hand - 1):
        return 1
    else:
        return 0

def deal_series_of_hands(num_hands,cards_per_hand):
    '''Deals a series of hands of cards and tests
    for single pairs in each hand.  Creates a deck
    of 52 cards, then begins dealing loop.  Shuffles
    deck thoroughly after each hand is dealt.
    Captures a list of the dealt hands that conform
    to the spec (i.e., that contain one pair each),
    for later debugging purposes
    Input:  int, int
    Output:  int, int, list
    '''
    deck = make_deck()
    single_pair_count = 0
    hand_capture = []
    for m in range(num_hands):
        shuffle_deck(deck)
        hand = deck[0:cards_per_hand]    #first cards dealt from the deck
        pair_count = test_for_single_pair(hand, cards_per_hand)
        if pair_count == 1:
            single_pair_count += pair_count
            hand_capture.append(hand)
    return (single_pair_count, num_hands, hand_capture)

cards_per_hand = 7   #User input parameter
num_hands = 50000    #user input parameter
single_pair_count, num_hands_dealt, hand_capture = deal_series_of_hands(num_hands, cards_per_hand)
single_pair_probability = single_pair_count/ num_hands_dealt
single_pair_str = 'Single pair probability (%d card deal; poker hands): '%(cards_per_hand)
print(single_pair_str, single_pair_probability)

如果手包含一个对,但还包含一个高价值单元,例如直线或冲洗,则您的代码仍然算作一对,而概率文章则没有。

最新更新