所以我试图运行一堆价格的模拟是正确的“展示台摊牌”。基本上,有三名球员。这个游戏是在一个巨大的轮子上演出的,这个巨轮上面充满了5分的5分增量到1美分的各种分值。并以该顺序(5¢,$ 1.00,15¢,80¢,35¢,60¢,20¢,40¢,75¢,55¢,95¢,50¢,85¢,30¢,65¢,10 ¢,45¢,70¢,25¢,90¢)。的价格是正确的“展示台摊牌”
游戏的目的是要来尽可能接近新台币$ 30元,你可以,但是不能超出。任何超过$ 1.00的东西都会丢失游戏。每位选手最多需要旋转两圈;在第一次旋转之后,旋转器可以选择停留在他/她所着陆或旋转的位置上;在第二次旋转中,无论参赛者的命中将被添加到第一个分数,并且(如前所述),如果他/她超过1.00美元,则该参赛者将从游戏中被淘汰;否则,该玩家站在记分牌下等待它。 当所有三名选手都参加了他们的旋转时,最接近1.00美元的选手将赢得比赛
所以我想对玩家1的第一个旋转是$ .50并且他再次旋转时发生的一系列模拟运行。所以它会产生一个随机旋转,如果它超过1.00美元就会失败,但如果它没有超过,玩家2就会旋转。玩家2要么击败玩家1要么破灭,如果他们破灭,玩家3会去。该代码会记录玩家1获得的胜负数。
问题是,不管我把为玩家1的初始值($ .50 $ .40,.30 $,$ .60,等...)的胜率始终是15%,这是不正确的。有任何想法吗?我知道代码是丑陋,但会原谅我是一个小白,并努力学习
from random import randint
def test(spin):
w=0
l=0
ties=0
gain=0
wins=0
tests=100000
for i in range(tests):
new=spin+5*randint(1,21) #new money value
if new>100: #if new value is over 100
l+=1 # you lose
else:
p2_spin_one=5*randint(1,21) #p2's first spin
if p2_spin_one>=new: #if its higher than p1's final
l+=1 #p1 loses
else:
p2_spin_two=p2_spin_one+5*randint(1,21) #if its lower,
#spin again
if p2_spin_two>new and p2_spin_two<=100: #if its higher
#and less than 100
l+=1 #p1 loses
else:
p3_spin_one=5*randint(1,21) #p3's first spin
if p3_spin_one>=new: #if its higher than p1's final
l+=1 #p1 loses
else:
p3_spin_two=p3_spin_one+5*randint(1,21) #if its
#lower, spin again
if p3_spin_two>new and p3_spin_two<=100: #if second
#spin is higher and less than 100
l+=1
elif new==p2_spin_two and new==p3_spin_two:
ties+=1
elif p2_spin_two>100 and new==p3_spin_two:
ties+=1
elif p2_spin_two<new and new==p3_spin_two:
ties+=1
elif new==p2_spin_two and p3_spin_two<new:
ties+=1
elif new==p2_spin_two and p3_spin_two>100:
ties+=1
else:
w+=1
return ("\nPlayer 1 spin again when first spin is
"+str(first_spin)+"\n\n"+"Wins:"+str(w)+"\nLosses:"+str(l)+"\nTies:
"+str(ties)+"\nWin Percentage: "+str(100*w/tests)+"%")
#Set This equal to the number the person spun first
first_spin=30
print(test(first_spin))
好吧,我明白了。你是对的,我没有尝试每一个价值,只有少数。如何让它在像这样的视觉吸引力的桌子上打印出来? –
查看有关** print **格式的任何在线教程。大多数情况下,我只是用制表符替换你的新行字符。 – Prune