저는 John Zelle의 Python Programming 문제를 해결하기 위해 노력해 왔습니다. 문제는 블랙 잭 딜러가 블랙 잭 딜러에게 그가 17 세가 될 때까지 치지 않으면 안되는 규칙을 부여하는 시간 비율을 보여주는 기본적인 블랙 잭 프로그램을 설계하는 것입니다.이 프로그램은 각 초기 카드에 대한 확률을 보여주기 위해 설계되었습니다. 딜러는 종종 첫 번째 카드를 공개합니다.Blackjack이 잘못된 딜러 비율을 다시 제공합니다.
내가 겪었던 문제는 Ace와 Ten을 제외한 모든 값에 대해 프로그램에서 블랙 잭 테이블을 참조 할 때 좋은 백분율을 제공하는 것 같습니다.
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 = 1,000,000 인 경우 온라인 테이블의 17 % 및 23 %와 크게 다른 11.5 %와 21.2 %를 얻습니다. 아무도 내게 문제가 뭔지 알려 줄 수 있니?
문제를 격리하려고 시도한 대상이 무엇입니까? 계산은 무엇입니까? – Marcin
딜러 카드를 사용하고 사용하는 카드를 제거하지 않을 수도 있습니까? (실제로 문제가 있는지 전혀 모른다. .. 그러나 그것은 있을지도 모른다. ..) –
@JoranBeasley - 이것은 나의 생각이었다. 차이점은 너무 높아 보이지만 ... – mgilson