正しいと思うコードを思いついたので、前の質問を編集しました。この背後にあるロジックは次のようになります: セットが終了しておらず、引き分けではない 10:10: プレーヤー A がサーブを開始し、ポイントを獲得するかどうかに関係なく 2 回サーブを行い、その後、プレーヤー B がサーブを受け取り、それを 2 回行います。サーバーが得点する各ポイントを変更する10:10の同点があることを除いて、セットが終了するまで続きます。
コードが完璧かどうかを確認できる人はいますか? ありがとうございました。
def simOneSet(probA, probB):
serving = "A"
scoreA = scoreB = 0
while not setOver(scoreA, scoreB):
if scoreA != 10 and scoreB != 10:
if serving == "A":
for i in range(2):
if random() < probA:
scoreA += 1
else:
scoreB += 1
serving = "B"
else:
for i in range(2):
if random() < probB:
scoreB +=1
else:
scoreA += 1
serving = "A"
# when there is a tie 10:10
else:
if serving == "A":
if random() < probA:
scoreA += 1
serving = "B"
else:
scoreB += 1
serving = "B"
else:
if random() < probB:
scoreB += 1
serving = "B"
else:
scoreA += 1
serving = "A"
return scoreA, scoreB