ãã«ã©ã®åçã®è¨ç®
ã«ã¸ãã§ãã«ã©ãéãã§ã¿ã¦ãããã¯ããã人ãå¤ãã®ãé ·ããã¨ããææ³ãæã£ããã»ã¨ãã©åç´ãªä¸ååæãªã®ã§ãããå¾ã ã«ç¶æ ã確å®ãã¦ããæ¼åºããã£ã¦ãå½ãã£ãã¨ãã®ãã¯ãã¨æ°ãèãä¸ããæè¦ãã¯ã»ã«ãªãã¾ãã次ã«ãã£ãã¨ãã«ãã£ã¨æ¥½ãããããã«ãå°ããã«ã©ã®çµ±è¨ã調ã¹ã¦éãã§ã¿ããã¨æãã
ä»æ¥ã¯ï¼åã®ã²ã¼ã ã§ã®ç¢ºçã調ã¹ã¦ã¿ã¾ããã¢ã³ãã«ã«ãæ³ã§ããã®ãè¸ããªãã®ã§ãé å¼µã£ã¦æè¨ç®ã§èª¿ã¹ã¦ããã¾ãããããã ãã«ã©ã®ã«ã¼ã«ã¯è¤éã ãããç´ã¨éçã ã¨ééã£ã¦ãã¾ãã®ã§ãPython ã§ã³ã¼ããæ¸ããªãããã£ã¦ããã¾ãã
åçã®è¨ç®
ã¾ãã¯ãã¬ã¼ã¤ã¼ããã³ã«ã¼ããããã®åçãæ±ãã¾ãããã¬ã¼ã¤ã¼ãåã¤å ´åãå ´ååããã¦ãããããã®ç¢ºçãæ±ãã¦ã足ãåãããã¨ããããããã¦ã³ã®ã¢ããã¼ãã§ãè¨ç®ã§ãã¾ãããä»åã¯ãããããªæ¡ä»¶ä¸ã§ã®ç¢ºçãè¨ç®ãã¦ã¿ããã®ã§ãããã ã¢ãããªã¢ããã¼ãã§ãã£ã¦ã¿ããã¨æãã¾ããçµå±ã¯ãããã§ãåããã¨ã§ããã
ã¾ãããã¬ã¼ã¤ã¼ã¨ãã³ã«ã¼ã«ã«ã¼ããå ¨ã¦é ããã¦ææã確å®ããç¶æ ã®ãã¹ã¦ã®å ´åã®ããããã®ç¢ºçãè¨ç®ãã¦ãã¾ãã¾ããããç´ã¨éçã ã¨ããªãã¤ããã§ãããè¨ç®æ©ä¸ã§ãã£ã¦ããã®ã§ãããããã¨ãã§ãã¾ãã
ææã®ç¶æ
ã¨ãããå ´ã®ç¶æ
ã表ããã¼ã¿æ§é Hand
ãå®ç¾©ãã¾ãã
Hand = namedtuple('Hand', ["player", "banker"])
player
ãã£ã¼ã«ãããã¬ã¼ã¤ã¼ã®ã«ã¼ããbanker
ãã£ã¼ã«ãããã³ã«ã¼ã®ã«ã¼ãã§ãããããã«é
ãããã«ã¼ãã®ã¿ãã«ãå
¥ãã¾ããä¾ãã° ãã¬ã¼ã¤ã¼ã A, J, 5 ã§ãã³ã«ã¼ã 2, 3, 4 ã®ã«ã¼ããé ã«å¼ããããªããHand(player=(1,0,5), banker=(2,3,4))
ã¨ãªãã¾ãã3æç®ãå¼ããªãå ´å㯠ã¿ãã«ã®ï¼ã¤ç®ã¯ None ã§ãã10, J, Q, K ãåºå¥ããå¿
è¦ã¯ãªãã®ã§ãããã®ã«ã¼ãã¯ãã¹ã¦0ã§è¡¨ãã¾ãããã
ãã® Hand
åã®å¤ ããã¼ã¨ãã¦ãHand
ã示ãææã®ç¶æ
ã«ãªã確çã p_hand
ã®é£æ³é
åã«å
¥ãã¦ããã¾ãã
p_hand = dict()
ãã¹ã¦ã®ã«ã¼ãã®å ´åã for ã«ã¼ããåãã¦ããããã®ç¢ºçãè¨ç®ãã¦ãã¾ãã
# ãã¹ã¦ã®æåï¼æã®å ´åã«ã¤ã㦠for p1, p2, b1, b2 in product(list(range(10)), repeat=4): # æåï¼æã®ç¹æ° p = (p1 + p2) % 10 b = (b1 + b2) % 10 # ãã¬ã¼ã¤ã¼ããã³ã«ã¼ã両æ¹ã¨ã2æã®ã¨ãã if p >= 8 or b >= 8 or (6 <= p <= 7 and 6 <= b <= 7): hand = Hand(player=(p1,p2,None), banker=(b1,b2,None)) p_hand[hand] = p_cards(p1,p2,b1,b2) continue # ãã¬ã¼ã¤ã¼ãï¼æç®ãå¼ãã if p <= 5: for p3 in range(10): # ãã¼ãã«ã«å¾ã£ã¦ããã³ã«ã¼ãï¼æç®ãå¼ãããå¤æããã if HIT_TABLE[b][p3]: for b3 in range(10): hand = Hand(player=(p1,p2,p3), banker=(b1,b2,b3)) p_hand[hand] = p_cards(p1,p2,p3,b1,b2,b3) continue # ãã³ã«ã¼ã¯3æç®ãå¼ããªãã hand = Hand(player=(p1,p2,p3), banker=(b1,b2,None)) p_hand[hand] = p_hand[hand] = p_cards(p1,p2,p3,b1,b2) continue # ãã³ã«ã¼ã®ã¿ï¼æç®ãå¼ã for b3 in range(10): hand = Hand(player=(p1,p2,None), banker=(b1,b2,b3)) p_hand[hand] = p_cards(p1,p2,b1,b2,b3)
ãã¦ãp_cards
ã¯å¼æ°ã®ã«ã¼ããå¼ã確çã¨ãªãã¾ããfor ã«ã¼ãã§å ´ã®ç¶æ
ãå
¨ã¦æ°ãä¸ãã¦ãããããã®ç¶æ
ã«ãªã確çãæ±ãã¦ãã£ã¦ãã¾ããp_cards
ã¯ä»¥ä¸ã§è¨ç®ãã¾ããã
def p_cards(*cards): """å¼æ°ã«ä¸ããããã«ã¼ããå¼ã確ç""" # 8 ãããã¨ä»®å®ããã N = 8 # 0 ãã 9 ã®ã«ã¼ãã®ææ°ã deck = [4 * 13 * N] + [13 * N for i in range(1, 10)] p = 1.0 for c in cards: # ã»ããã«ã¼ãããªããªã£ãå ´åã¯ç¢ºç0 if deck[c] <= 0: return 0.0 p *= deck[c] / sum(deck) deck[c] -= 1 return p
ï¼ãããã¨ãã¦ãã«ã¼ãã®å±±ã®ä¸ã®ã»ããã«ã¼ãã®å²å½ããããããã¦ãã¾ããã«ã¼ããå°½ããå ´åã¯æ¸ãããã«0ãè¿ãã¾ãã
ï¼ã²ã¼ã ç®ä»¥éã¯ã«ã¼ããæ¸ã£ã¦ããã®ã§ã以åã®ã²ã¼ã ã®çµæãåæ ããã¨ç¢ºçã¯å¤ãã£ã¦ãã¾ããããããã«ã¦ã³ãã£ã³ã°ã¯å¼ã°ããå¿
åæ³ã¯ãã®åçãå©ç¨ãã¾ããããããçµãã£ãã²ã¼ã ã®ç¥èãåæ ããªãç«å ´ã«ç«ã¤ãªããä½åç®ã®ã²ã¼ã ã§ã欲ããã«ã¼ããå¼ã確çã¯åãã§ãããã®ãããdeck
ãæ¯ååãå¤ã§åæåãã¦ãçµæã¯å¤ããã¾ããã
HIT_TABLE
ã¯ä»¥ä¸ã§ãããã£ã¼ã©ã¯ãããæè¨ãã¦ééããªãããã«ããªããã°ãªããªãã®ã§ã大å¤ã§ããã人ãããä»äºã§ã¯ãªããã人ãããããé¢ç½ãã娯楽ã¨ã¯ãããããã®ã§ãã
# 縦ã Banker ã®ï¼æç®ã¾ã§ã®ç¹æ°ã横ãPlayer ã®ï¼æç®ã®ã«ã¼ã HIT_TABLE = [ [1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,0,1], [0,0,1,1,1,1,1,1,0,0], [0,0,0,0,1,1,1,1,0,0], [0,0,0,0,0,0,1,1,0,0], [0,0,0,0,0,0,0,0,0,0], ]
ããã§ï¼ã²ã¼ã ãçµãã£ãã¨ãã®ãã¹ã¦ã®ç¶æ ã¨ãã®ç¢ºçãæãããã¨ãã§ãã¾ãããå ¨é¨ã§ 339400 éãã®ç¶æ ãããã¾ããã
ãã¬ã¼ã¤ããã³ã«ã¼ããããã®åçãã¿ã¤ã¨ãªã確çã¯ãç¶æ 群ãã欲ããå ´åããã£ã«ã¿ã¼ãã¦ç¢ºçã足ãåãããã°è¨ç®ã§ãã¾ãã
def point(hand): return sum(card for card in hand if card) % 10 player_win = sum(p for h, p in p_hand.items() if point(h.player) > point(h.banker)) banker_win = sum(p for h, p in p_hand.items() if point(h.player) < point(h.banker)) tie = sum(p for h, p in p_hand.items() if point(h.player) == point(h.banker))
çµæ以ä¸ã®ãããªå¤ãå¾ã¾ããã
Winner | Probability |
---|---|
Player | 0.446177979 |
Banker | 0.458480647 |
Tie | 0.095341374 |
ããã£ã½ãå¤ãå¾ããã¨ãã§ãã¾ããããµã¤ãã«ãã£ã¦å¤ãéãã®ã¯ãããã®æ°ãªã©ç½®ãã¦ããä»®å®ãéã£ãããã¦ããã®ã ã¨æããã¾ãã
次ã«è²ã ãªå ´åã®ç¢ºçãæ±ãã¦ããã¾ãããã
ã«ã¼ããå¼ãææ°
ãã¬ã¼ã¤ã®æ¯æ° | ãã³ã«ã¼ã®æ¯æ° | 確ç |
---|---|---|
2 | 2 | 0.378750705 |
3 | 2 | 0.185579254 |
2 | 3 | 0.117666050 |
3 | 3 | 0.318003992 |
4å²å¼±ã®ã²ã¼ã ã¯æåã®ï¼æã§çµããã¾ããã¾ããã³ã«ã¼ã ãå¼ãå ´åã¯å°ãªãããã§ããæè¦ã«ãã£ã¦ã¾ããã
æåï¼æãåãã£ããã¨ã®åç
ãã«ã©ã®ééå³ã¯ãï¼æç®ããã¨ããé ãããããã«ã¼ããçµã£ã¦ããã£ãããã¦ãç¶æ ãå¾ã ã«ç¢ºå®ãã¦ããã¨ããã§ããããæåï¼æã確å®ãã¦ããç¶æ ã§ããã®å¾ã®åçãè¦ã¦ããã¾ãããã
ãã³ã«ã¼ããã¬ã¼ã¤ã¼ã®ããããã®æåï¼æãæãããªç¶æ ã§ã®ãããçæ¹ã®åçã¯ä»¥ä¸ã®ã¨ããã¨ãªãã¾ãããã ããå¼ãåãã®å ´åã¯é¤ãã¦ãã¾ãã
ãã³ã«ã¼ã®æåï¼æã®ç¹æ° | ãã¬ã¼ã¤ã¼ã®åç | ãã¬ã¼ã¤ã¼ã®æåï¼æã®ç¹æ° | ãã³ã«ã¼ã®åç |
---|---|---|---|
0 | 0.699536232 | 0 | 0.701654826 |
1 | 0.680185869 | 1 | 0.695725285 |
2 | 0.662796859 | 2 | 0.685655013 |
3 | 0.645613308 | 3 | 0.669359519 |
4 | 0.613826427 | 4 | 0.642328585 |
5 | 0.556476320 | 5 | 0.600026889 |
6 | 0.497409035 | 6 | 0.498438328 |
7 | 0.332291914 | 7 | 0.332291914 |
8 | 0.104645082 | 8 | 0.104645082 |
9 | 0.000000000 | 9 | 0.000000000 |
åºæ¬çã«ç¹æ°ã9 ã«éãã»ã©æå©ã§ããç¸æãï¼ã ã¨ãã§ã«è² ãã確å®ãã¦ãã¦ã 8ã§ãã»ã¼è² ãã§ããããããç¸æã 0 ã§ãã£ã¦ããæ²¹æã¯ã§ããªããã¨ããããã¾ããçµãã¨ãã®å¿µãæ¹ãéè¦ã ã¨è¨ããã§ãããã
3æç®ä»¥éã®é転ã®å¯è½æ§
åæ¹ã®æåã®ï¼æã確å®ãã¦ããã®å¾ã«é転ããå¯è½æ§ã調ã¹ã¦ã¿ã¾ãã
æåï¼æã®ãã¬ã¼ã¤ã¼ã¨ãã³ã«ã¼ã®ç¹æ°å·®ã¨ãã¬ã¼ã¤ã¼ã®åçã®é¢ä¿ã¯ä»¥ä¸ã®ã¨ããã§ããï¼æç®ã§åæã確å®ãã¦ããå ´åã¨å¼ãåãã®å ´åã¯é¤å¤ãã¦ãã¾ãã
ç¹æ°å·® | ãã¬ã¼ã¤ã¼ã®åç |
---|---|
-7 | 0.166794800 |
-6 | 0.222154613 |
-5 | 0.256331981 |
-4 | 0.286572484 |
-3 | 0.307923668 |
-2 | 0.331206776 |
-1 | 0.387202181 |
0 | 0.496529573 |
1 | 0.595966939 |
2 | 0.640109980 |
3 | 0.662224521 |
4 | 0.689246802 |
5 | 0.720494534 |
6 | 0.782535047 |
7 | 0.833205200 |
åºæ¬çã«ç¹æ°å·®ã大ããæ¹ãæå©ãªããã§ããããããï¼æç®ä»¥éã®ã«ã¼ãã§é転ã®å¯è½æ§ãæ®ããã¦ãã¾ããé©åº¦ã«é転ã®å¯è½æ§ããã£ã¦ãã²ã¼ã ãã©ã³ã¹ãããã¨æãã¾ããããã ã«ã¼ããå¼ãããã®ãçºãã¦ããã ããªã®ã§ããããã®ãããã®ãã©ãã©ããããããã«ã©ã®é åã ã¨æãã¾ãã