所以,我一直在研究John Zelle編程的一個問題。問題在於設計一個基本的21點遊戲程序,該程序演示了一個二十一點經銷商在超過17歲之前必須擊中的規則會佔多大比例。該程序旨在顯示每張初始卡的可能性百分比,因爲經銷商經常透露他的第一張牌。大酒杯回饋錯誤的經銷商百分比
我遇到的問題是,程序似乎給我很好的百分比,除了Ace和十,當我交叉引用他們與二十一點表。
from random import randrange
def main():
printIntro()
n = getInput()
busts = simBlackjack(n)
printSummary(n, busts)
def printIntro():
print "Hello, and welcome to Blackjack.py."
print "This program simulates the likelihood"
print "for a dealer to bust."
def getInput():
n = input("How many games do you wish to simulate: ")
return n
def simBlackjack(n):
busts = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for b in range(10):
for i in range(n):
x = b + 1
if b == 0:
handAce = True
else: handAce = False
while x < 17:
add = randrange(1,14)
if add == 11:
add = 10
elif add == 12:
add = 10
elif add == 13:
add = 10
elif add == 1:
handAce = True
x = x + add
if handAce:
if x + 10 >= 17 and x + 10 <= 21:
x = x + 10
if x > 21:
busts[b] = busts[b] + 1
return busts
def printSummary(n, busts):
for b in range(10):
if b == 0:
print "When the initial card was Ace, the dealer busted %d times in %d games. (%0.1f%%)" % (busts[0], n, (busts[0])/float(n) * 100)
else:
print "When the initial value was %d, the dealer busted %d times in %d games. (%0.1f%%)" % ((b + 1), busts[b], n, (busts[b])/float(n) * 100)
if __name__ == "__main__": main()
如果n = 100萬,我得到〜11.5%和21.2%,從17%相差23%,網上表格顯著保持。有人可以讓我知道問題是什麼嗎?
你有什麼試圖找出問題的原因?計算應該是什麼? – Marcin
可能是因爲您只使用經銷商手中的一套房而不移除使用的卡? (不知道這是否是實際問題......但它可能是......) –
@JoranBeasley--這也是我的想法。雖然...差異似乎過高... – mgilson