# 一共比赛是五局三胜(就是五局)
# 前四局 先达到25分而且超两分
# 最后一局先达到15赢(决赛时达到8分后换场地)
# 能力值通过随机数来进行比赛得分模拟
from random import random
def SC():
input("这个程序是模拟队伍A和队伍B的排球竞技比赛")
input("需要A队伍和B队伍的能力值(以0.1到0.01之间的小数表示)")
def BS1(PA, PB):
SJ = "a"
SA, SB = 0, 0
while not (SA == 25 or SB == 25):
if SJ == "a":
if PA > random():
SA += 1
SJ = "a"
else:
SJ = "b"
else:
if PB > random():
SB += 1
SJ = "b"
else:
SJ = "a"
return SA, SB
def BS3(PA, PB):
SA, SB = 0, 0
SJ = "a"
while not (SA == 15 or SB == 15):
if SJ == "a":
if PA > random():
SA += 1
SJ = "a"
else:
SJ = "b"
else:
if PB > random():
SB += 1
SJ = "b"
else:
SJ = "a"
return SA, SB
def BS2(NLJA, NLJB):
winA, winB = 0, 0
for i in range(4):
SJA, SJB = BS1(NLJA, NLJB)
if SJA > SJB:
winA += 1
else:
winB += 1
if winA == winB:
SJA, SJB = BS2(NLJA, NLJB)
if SJA > SJB:
winA += 1
print("win:{}".format(winA))
else:
winB += 1
return winA, winB
SC()
a = eval(input("请输入A队伍的能力值(0-1):"))
b = eval(input("请输入B队伍的能力值(0-1):"))
winA, winB = BS2(a, b)
print("A队伍赢的次数为:{},获胜率为:{}".format(winA, winA / 5))
print("A队伍赢的次数为:{},获胜率为:{}".format(winB, winB / 5))
采用排球比赛规则
最新推荐文章于 2024-08-16 18:55:06 发布