石头剪刀布

关于“石头剪刀布”的一点点思考

人尽皆知的“石头剪刀布”游戏,一共两个玩家,而运行结果无非三种,A赢,B赢,平局,也就是说说三种结果的概率理论上应该都是1/3,总共有3X3=9中组合方式,下面用Python模拟这个过程

#Possiblity of mora game
from random import *
mora_GamerA=["Rock","Paper","Scissor"]
mora_GamerB=["Rock","Paper","Scissor"]
count_A_win=0
count_B_win=0
count_Draw=0
Flag=1
while Flag:
    round=int(input("Enetr rounds:(rounds>=10)"))
    if round<10:
        print("The input bureau does not meet the requirements")
        Flag=0
        break
    else:
        for round in range(1,round+1):
            print("Game round {}".format(round))
            guess_A=mora_GamerA[randint(0,2)]
            guess_B=mora_GamerB[randint(0,2)]
            """
            Attention the range of list index
            """
            if (guess_A=="Rock" and guess_B=="Scissor") or (guess_A=="Paper" and guess_B=="Rock") or (guess_A=="Scissor" and guess_B=="Paper"):
                count_A_win+=1
                print("A is {},B is {}".format(guess_A,guess_B))
                print("Gamer A is winner")
            elif guess_A==guess_B:
                count_Draw+=1
                print("A and B is {}".format(guess_A))
                print("Draw")
            else:
                count_B_win+=1
                print("A is {},B is {}".format(guess_A,guess_B))
                print("Gamer B is winner")
        print("In {} rounds,gamer A have won {} rounds and gamer B have won {} rounds,{} rounds is draw.".format(round,count_A_win,count_B_win,count_Draw))
        print("The possiblity of A win is {}".format(count_A_win/round))
        print("The possiblity of B win is {}".format(count_B_win/round))
        print("The possiblity of draw is {}".format(count_Draw/round))
        Flag=int(input("Enter 1 to continue and 0 to exit :"))
        if Flag!=1 and Flag!=0:
            Flag=0
            print("Force exit because mistake input")

运行之后发现并不是每一次的结果都完全对应1/3,但随着次数round的增加,三种概率会逐渐接近1/3这个值,因为实际上得出1/3是在理想条件下的结果,而“理想情况”需要大量的实验次数,这就是为什么在round大于100000以后取值越来越接近1/3的原因

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值