国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

一步步解析Python斗牛游戲的概率

來源:懂視網 責編:小采 時間:2020-11-27 14:35:19
文檔

一步步解析Python斗牛游戲的概率

一步步解析Python斗牛游戲的概率:過年回家,都會約上親朋好友聚聚會,會上經常會打麻將,斗地主,斗牛。在這些游戲中,斗牛是最受歡迎的,因為可以很多人一起玩,而且沒有技術含量,都是看運氣(專業術語是概率)。 斗牛的玩法是: 1、把牌中的JQK都拿出來 2、每個人發5張牌 3、如果5張
推薦度:
導讀一步步解析Python斗牛游戲的概率:過年回家,都會約上親朋好友聚聚會,會上經常會打麻將,斗地主,斗牛。在這些游戲中,斗牛是最受歡迎的,因為可以很多人一起玩,而且沒有技術含量,都是看運氣(專業術語是概率)。 斗牛的玩法是: 1、把牌中的JQK都拿出來 2、每個人發5張牌 3、如果5張

過年回家,都會約上親朋好友聚聚會,會上經常會打麻將,斗地主,斗牛。在這些游戲中,斗牛是最受歡迎的,因為可以很多人一起玩,而且沒有技術含量,都是看運氣(專業術語是概率)。
斗牛的玩法是:

  • 1、把牌中的JQK都拿出來
  • 2、每個人發5張牌
  • 3、如果5張牌中任意三張加在一起是10的 倍數,就是有牛。剩下兩張牌的和的10的余數就是牛數。
  • 牌的大小:

    4條 > 3條 > 牛十 > 牛九 > …… > 牛一 >沒有牛

    而這些牌出現的概率是有多少呢?

    由于只有四十張牌,所以采用了既簡單,又有效率的方法枚舉來計算。
    計算的結果:

  • 所有牌的組合數:658008
  • 出現四條的組合數:360,概率 :0.05%
  • 出現三條的組合數:25200,概率 :3.83%
  • 出現牛十的組合數:42432,概率 :6.45%
  • 出現牛九或牛八的組合數:87296,概率 :13.27%
  • 出現牛一到牛七的組合數:306112,概率 :46.52%
  • 出現沒有牛的組合數:196608,概率 :29.88%
  • 所以有七成的概率是有牛或以上的,所以如果你經常遇到沒有牛,說明你的運氣非常差或者本來是有牛的,但是你沒有找出來。

    Python源代碼:

    # encoding=utf-8
    __author__ = 'kevinlu1010@qq.com'
    import os
    import cPickle
    
    from copy import copy
    from collections import Counter
    import itertools
    '''
    計算斗牛游戲的概率
    '''
    
    class Poker():
     '''
     一張牌
     '''
    
     def __init__(self, num, type):
     self.num = num # 牌數
     self.type = type # 花色
    
    
    class GamePoker():
     '''
     一手牌,即5張Poker
     '''
     COMMON_NIU = 1 # 普通的牛,即牛一-牛七
     NO_NIU = 0 # 沒有牛
     EIGHT_NINE_NIU = 2 # 牛九或牛八
     TEN_NIU = 3 # 牛十
     THREE_SAME = 4 # 三條
     FOUR_SAME = 5 # 四條
    
     def __init__(self, pokers):
     assert len(pokers) == 5
     self.pokers = pokers
     self.num_pokers = [p.num for p in self.pokers]
     # self.weight = None # 牌的權重,權重大的牌勝
     # self.money_weight = None # 如果該牌贏,贏錢的權重
     self.result = self.sumary()
    
     def is_niu(self):
     '''
     是否有牛
     :return:
     '''
     # if self.is_three_same():
     # return 0
     for three in itertools.combinations(self.num_pokers, 3):
     if sum(three) % 10 == 0:
     left = copy(self.num_pokers)
     for item in three:
     left.remove(item)
     point = sum(left) % 10
     return 10 if point == 0 else point
    
     return 0
    
     def is_three_same(self):
     '''
     是否3條
     :return:
     '''
     # if self.is_four_same():
     # return 0
     count = Counter([p.num for p in self.pokers])
     for num in count:
     if count[num] == 3:
     return num
     return 0
    
     def is_four_same(self):
     '''
     是否4條
     :return:
     '''
     count = Counter([p.num for p in self.pokers])
     for num in count:
     if count[num] == 4:
     return num
     return 0
    
     def sumary(self):
     '''
     計算牌
     '''
     if self.is_four_same():
     return GamePoker.FOUR_SAME
     if self.is_three_same():
     return GamePoker.THREE_SAME
     niu_point = self.is_niu()
     if niu_point in (8, 9):
     return GamePoker.EIGHT_NINE_NIU
     elif niu_point == 10:
     return GamePoker.TEN_NIU
     elif niu_point > 0:
     return GamePoker.COMMON_NIU
     else:
     return GamePoker.NO_NIU
    
    def get_all_pokers():
     '''
     生成所有的Poker,共四十個
     :return:
     '''
     pokers = []
     for i in range(1, 11):
     for j in ('A', 'B', 'C', 'D'):
     pokers.append(Poker(i, j))
    
     return pokers
    
    
    def get_all_game_poker(is_new=0):
     '''
     生成所有game_poker
     :param pokers:
     :return:
     '''
     pokers = get_all_pokers()
     game_pokers = []
    
     if not is_new and os.path.exists('game_pokers'):
     with open('game_pokers', 'r') as f:
     return cPickle.loads(f.read())
    
     for pokers in itertools.combinations(pokers, 5): # 5代表五張牌
     game_pokers.append(GamePoker(pokers))
     with open('game_pokers', 'w') as f:
     f.write(cPickle.dumps(game_pokers))
     return game_pokers
    
    
    def print_rate(game_pokers):
     total_num = float(len(game_pokers))
     four_num = len([game_poker for game_poker in game_pokers if game_poker.result == GamePoker.FOUR_SAME])
     three_num = len([game_poker for game_poker in game_pokers if game_poker.result == GamePoker.THREE_SAME])
     ten_num = len([game_poker for game_poker in game_pokers if game_poker.result == GamePoker.TEN_NIU])
     eight_nine_num = len([game_poker for game_poker in game_pokers if game_poker.result == GamePoker.EIGHT_NINE_NIU])
     common_num = len([game_poker for game_poker in game_pokers if game_poker.result == GamePoker.COMMON_NIU])
     no_num = len([game_poker for game_poker in game_pokers if game_poker.result == GamePoker.NO_NIU])
     print '所有牌的組合數:%d' % total_num
     print '出現四條的組合數:%d,概率 :%.2f%%' % (four_num, four_num * 100 / total_num)
     print '出現三條的組合數:%d,概率 :%.2f%%' % (three_num, three_num * 100 / total_num)
     print '出現牛十的組合數:%d,概率 :%.2f%%' % (ten_num, ten_num * 100 / total_num)
     print '出現牛九或牛八的組合數:%d,概率 :%.2f%%' % (eight_nine_num, eight_nine_num * 100 / total_num)
     print '出現牛一到牛七的組合數:%d,概率 :%.2f%%' % (common_num, common_num * 100 / total_num)
     print '出現沒有牛的組合數:%d,概率 :%.2f%%' % (no_num, no_num * 100 / total_num)
    
    
    def main():
     game_pokers = get_all_game_poker() # 658008種
     print_rate(game_pokers)
    
    
    main()
    

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    一步步解析Python斗牛游戲的概率

    一步步解析Python斗牛游戲的概率:過年回家,都會約上親朋好友聚聚會,會上經常會打麻將,斗地主,斗牛。在這些游戲中,斗牛是最受歡迎的,因為可以很多人一起玩,而且沒有技術含量,都是看運氣(專業術語是概率)。 斗牛的玩法是: 1、把牌中的JQK都拿出來 2、每個人發5張牌 3、如果5張
    推薦度:
    標簽: 游戲 斗牛 分析
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 久艹网 | 成人久久久精品乱码一区二区三区 | 欧美精品第二页 | 国产精品高清一区二区三区不卡 | 一级毛片视频播放 | 久操综合| 国产成人一区二区小说 | 日本韩国在线 | 欧美一区三区 | 国产成人精品.一二区 | 国产精品久久久久影院色 | 国模私拍一区二区 | 最新国产精品精品视频 | 欧美自拍亚洲 | 日韩高清一区 | 欧美日韩在线观看视频 | 国产美女一区二区 | 一区免费在线观看 | 国产一区二区三区精品视频 | 国产又黄又爽的视频 | 亚洲综合一区二区精品久久 | 日韩中文在线观看 | 精品久久中文网址 | 亚洲国产成人精品一区二区三区 | 亚洲一级二级 | 永久免费观看的毛片的网站 | 国产高清不卡一区二区三区 | 免费观看日韩大尺码观看 | 在线视频你懂 | 国产成人91一区二区三区 | 欧美日韩亚洲高清不卡一区二区三区 | 国产精品糟蹋漂亮女教师 | 国产91免费 | 222aaa免费国产在线观看 | 91视频中文字幕 | 国产麻豆a一级毛片爽爽影院 | 伊人久久91 | 国产成人精品久久一区二区三区 | 伊人久久成人成综合网222 | 成人欧美一区二区三区视频不卡 | 亚欧美|