围棋比赛通过概率

 我来答
舒适还明净的海鸥i
2022-07-22 · TA获得超过1.7万个赞
知道小有建树答主
回答量:380
采纳率:0%
帮助的人:69.3万
展开全部
孩子参加上海围棋升级赛,规则是

1级者7局5胜升至初段

2级者7局5胜升至1级

3级至5级7局4胜升一级

6级至8级6局3胜升一级

9级至10级5局2胜升一级

同时,如果一场比赛中,如果已经胜利了可以升级的场数,就不需要再比了,如果失败了剩余比赛都胜利了也一定升不了级的场数,也不需要再比了。

对于升级的概率比较感兴趣,写了个模拟程序。算出大概的通过率是

1级者7局5胜升至初段 5/7 17%

2级者7局5胜升至1级 5/7 17%

3级至5级7局4胜升一级 4/7 50%

6级至8级6局3胜升一级 3/6 66%

9级至10级5局2胜升一级 2/5 80%

可以看出,一开始通过率很高,到后面升级还是很困难的。

程序如下:

'''

simulate 100 player

how to match: play with adjacent player

each player has 50% rate to win

if play win win_count_to_pass times, it is passed, no need to match

if player failed (total_games-win_count_to_pass+1) times, no need to match

'''

import random

def check_if_passed(list_item, win_count_to_pass):

    cnt=0

    for i in range(7):

        if list_item[i+1] is True:

            cnt += 1

    if cnt >= win_count_to_pass:

        return True

    else:

        return False

def check_if_kicked(list_item, raced_cnt, total_games, win_count_to_pass):

    fail_cnt = total_games-win_count_to_pass+1  # for pass 2/5, fail 4 games will fail, for pass 5/7, fail 3 games will fail

    if raced_cnt<fail_cnt:  # have not race fail_cnt times

        return False

    cnt=0

    for i in range(raced_cnt):

        if list_item[i+1] is False:

            cnt += 1

    if cnt == fail_cnt:

        return True

    else:

        return False

# first round, 1 vs 2, 2 is already played with 1, so next loop start from 3

def check_if_raced(list_item, which_game):

    if list_item[which_game+1] is True:

        return True

    else:

        return False

def getPasRate(total_games, win_count_to_pass):

    students_win_list = []

    students_raced = []

    for i in range(100):

        students_win_list.append([i, False, False, False, False, False, False, False, False]) # last bool True indicate pass

        students_raced.append([i, False, False, False, False, False, False, False])

    for i in range(total_games):

        for j in range(0, 100):

            if check_if_raced(students_raced[j], i) or check_if_passed(students_win_list[j], win_count_to_pass) \

                    or check_if_kicked(students_win_list[j], i, total_games, win_count_to_pass):

                continue

            else:

                for k in range(j+1, 100):

                    if check_if_raced(students_raced[k], i) or check_if_passed(students_win_list[k], win_count_to_pass) \

                    or check_if_kicked(students_win_list[k], i, total_games, win_count_to_pass):

                        continue

                    else:

                        if random.randint(1,100) % 2 == 0: # j win

                            students_raced[j][i+1] = True

                            students_raced[k][i+1] = True

                            students_win_list[j][i+1] = True

                            students_win_list[k][i+1] = False

                            print("Race " + str(i+1) + ", player " + str(j) + " vs " + str(k) + ", player " + str(j) + " wins")

                        else: # k win

                            students_raced[j][i+1] = True

                            students_raced[k][i+1] = True

                            students_win_list[j][i+1] = False

                            students_win_list[k][i+1] = True

                            print("Race " + str(i+1) + ", player " + str(j) + " vs " + str(k) + ", player " + str(k) + " wins")

                        break # player 1 already played with 2, no need to play with others

    win_count = 0

    for i in range(100):

        if check_if_passed(students_win_list[i], win_count_to_pass):

            win_count += 1

            students_win_list[i][8] = True

        #print("player " + str(i) + ": ")

        #print(students_win_list[i])

    return win_count

if __name__ == '__main__':

    pass_count = getPasRate(5,2)

    print(pass_count)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式