您好,欢迎来到浩鑫科技。
搜索
您的当前位置:首页围棋比赛通过概率

围棋比赛通过概率

来源:浩鑫科技


孩子参加上海的围棋升级赛,规则如下:
1. 初学者(1级)需要在7场比赛中赢得5场才能晋升至初段。
2. 2级选手在7场比赛中赢得5场即可晋升至1级。
3. 3级至5级选手在7场比赛中赢得4场可晋升一级。
4. 6级至8级选手在6场比赛中赢得3场可晋升一级。
5. 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,即50%。
- 9级至10级选手在5场比赛中赢得2场晋升一级的概率为2/5,即80%。
由此可见,一开始通过率较高,但到了后面升级变得相当困难。
程序如下:
```python
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# 对于需要2/5胜率晋升的情况,失败3场将无法晋升;对于5/7胜率晋升的情况,失败2场将无法晋升
if raced_cnt < fail_cnt:# 还未达到失败的场次
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
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])# 最后的布尔值为True表示晋升
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赢
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赢
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# 玩家1已经与2对战,无需与其他玩家对战
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)
```
请注意,程序中的函数和变量命名应使用英文,以保持代码的清晰性和可读性。此外,程序中的打印语句可能会干扰输出结果的整齐性,建议在实际使用时移除或替换。

Copyright © 2019- haoxinyouxi.com 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务