PARS壁球比赛

时间:2016-12-05 18:27:47

标签: python-3.x

下面是我模拟PARS得分壁球比赛的代码:

import random
def game(ra, rb):
    prob_a = ra / (ra + rb)

    points_a = 0
    points_b = 0

    winning_score = 11

    while points_a < winning_score and points_b < winning_score:
        prob = random.random()
        if prob < prob_a:
            points_a += 1
        else:
            points_b += 1
    return(points_a, points_b)

game(70,30)

一切正常,但我不确定如何确保玩家a或b必须获得2分。

1 个答案:

答案 0 :(得分:0)

更改您的while语句,以便在分数过于接近时保持游戏正常运行。

while (points_a < winning_score and points_b < winning_score) or abs(points_a - points_b) < 2