因此,我正在尝试运行一堆模拟价格是正确的'Showcase Showdown‘。从本质上讲,有三个玩家。这个游戏是在一个被称为“大轮子”的巨大轮子上进行的,轮子上充满了从5美分一直到1.00美元的递增的各种分值;并且按照这个顺序(5美分,1.00美元,15美分,80美分,35美分,60美分,20美分,40美分,75美分,55美分,95美分,50美分,85美分,30美分,65美分,10美分,45美分,70美分,25美分,90美分)。
游戏的目标是在不超过1.00美元的情况下尽可能接近1.00美元。任何超过1.00美元的都会输掉这场游戏。每个玩家最多旋转两次轮子;在第一次旋转后,旋转者可以选择停留在他/她所在的位置或再次旋转;在第二次旋转中,无论参赛者点击什么,都将被添加到第一个分数中,并且(如前所述)如果他/她超过1.00美元,该参赛者将被淘汰出局;否则,该参赛者站在记分板下等待。当所有三名参赛者都完成旋转后,最接近1.00美元的参赛者将赢得比赛。
所以我想运行一组模拟,当玩家1的第一次旋转是$.50,然后他再次旋转时,会发生什么。所以它会产生一个随机的旋转,如果它超过1.00美元,他们就会输,但如果它没有超过,玩家2就会旋转。
问题是,无论我把什么作为玩家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))发布于 2017-10-05 08:47:40
我们不能解决这个问题,因为你所说的问题并不存在。首先,中奖百分比只有大约15%,并且在初始值50之后慢慢下降。如果你真的尝试了第一次旋转的所有20种可能性,以及建立一个合理的策略来决定第一个玩家是否应该进行第二次旋转,你会看到更好的结果。我修改了您的输出,并循环您的主程序以生成一个表:
for first_spin in range(5, 105, 5):
print(test(first_spin))输出:
spin 1:5 W:15736 L:82317 T:1947 Pct: 15.736%
spin 1:10 W:15597 L:82533 T:1870 Pct: 15.597%
spin 1:15 W:15623 L:82359 T:2018 Pct: 15.623%
spin 1:20 W:15700 L:82333 T:1967 Pct: 15.7%
spin 1:25 W:15604 L:82452 T:1944 Pct: 15.604%
spin 1:30 W:15623 L:82458 T:1919 Pct: 15.623%
spin 1:35 W:15598 L:82547 T:1855 Pct: 15.598%
spin 1:40 W:15411 L:82688 T:1901 Pct: 15.411%
spin 1:45 W:15382 L:82756 T:1862 Pct: 15.382%
spin 1:50 W:15004 L:83193 T:1803 Pct: 15.004%
spin 1:55 W:15037 L:83197 T:1766 Pct: 15.037%
spin 1:60 W:14346 L:83994 T:1660 Pct: 14.346%
spin 1:65 W:13800 L:84570 T:1630 Pct: 13.8%
spin 1:70 W:13064 L:85467 T:1469 Pct: 13.064%
spin 1:75 W:11878 L:86769 T:1353 Pct: 11.878%
spin 1:80 W:10587 L:88275 T:1138 Pct: 10.587%
spin 1:85 W:8586 L:90505 T:909 Pct: 8.586%
spin 1:90 W:6467 L:92845 T:688 Pct: 6.467%
spin 1:95 W:3450 L:96216 T:334 Pct: 3.45%
spin 1:100 W:0 L:100000 T:0 Pct: 0.0%第一个玩家拥有关于游戏的最少信息,因此具有最差的获胜百分比。
https://stackoverflow.com/questions/46576162
复制相似问题