所以,我一直在研究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