玩一个2人游戏,玩家A和B轮流从袋子里取出石头。
10颗宝石,9颗白色,1颗黑色
如果你抽到黑石头,你就输了。
假设你轮流抽石头,先走是优势、劣势还是中性?
我知道这可以用条件概率来解决,但我也想用大量的样本数据来证明这一点
import random
import os
import sys
stones = 4
player1Wins = 0
player2Wins = 0
no_games = 100000
gameCount = 0
fatal_stone = random.randint(1, int(stones))
picked_stone = random.randint(1, int(stones))
def pick_stone(self, stones):
for x in range(1, int(stones) + 1):
if picked_stone == fatal_stone:
if (picked_stone % 2) == 0:
player2Wins += 1 print("Player 2 won")
break
if (picked_stone % 2) == 1:
player1Wins += 1
print("Player 1 won")
break
else:
stones -= 1 picked_stone = random.randint(1, int(stones))
self.pick_stone()
pick_stone()
# def run_games(self, no_games): #for i in range(1, int(no_games) + 1): #gameCount = i #self.pick_stone()
print(fatal_stone)
print(picked_stone)
print(int(fatal_stone % 2))
print(int(picked_stone % 2))
print(gameCount)
print("Player 1 won this many times: " + str(player1Wins))
print("Player 2 won this many times: " + str(player2Wins))
1条答案
按热度按时间jmp7cifd1#
下面的代码是有效的,它表明无论谁先玩,双方获胜的机会都是相等的。