我想模擬使用英語規則的壁球比賽的得分。 這些是:我的代碼模擬一個壁球遊戲怎麼了?
- 只有服務器如果他們贏得一次集會就被授予一個點。
- 如果服務器贏得集會,他們會收到一個點並繼續作爲服務器。
- 如果返回者贏得集會,他們將成爲服務器,但不會得到一分。
- 除非得分已經達到8-8,否則第一名達到9分的球員將獲勝。
- 如果分數達到8-8,誰達到了8第一個決定是否發揮到9或至10
我的代碼的球員是這樣的:
import random
def eng_game(a,b):
A = 'bob'
B = 'susie'
players = [A, B]
server = random.choice(players)
print server
points_bob = 0
points_susie= 0
prob_A_wins = 0.4
prob_B_wins = 0.6
while points_bob or points_susie < 9:
probability = random.random()
print probability
if probability < prob_A_wins and server == A:
points_bob += 1
elif probability < prob_A_wins and server == B:
server == A
print server
if probability > prob_A_wins and server == B:
points_susie += 1
elif probability > prob_A_wins and server == A:
server == B
print server
print points_bob
print points_susie
此代碼返回Susie獲勝9-0,在某些情況下,服務器應該交換給Bob贏得這一點,但這不會發生。發球局保持與蘇西,她贏得了這一點。
說明你的代碼做錯了什麼(或者是否給出錯誤或異常)會有幫助。 –
哦是啊對不起,現在編輯它 – user1902151