Players A, B take turns making a shot. If the player fails to make a shot while the player before him does make a shot, he gets a point. If he misses the shot while the player before him also misses, nothing happens, and the next player shoots.
When someone accrues five points, they are eliminated from the game. The remaining player is the winner.
I want code that takes two variables(The probability a that A will make a shot and the probability b that B will make a shot) and then simulates a game. If player A wins, output 0, if player b wins, outputs 1.
I am very bad at programing, so forgive what I have tried to do so far.
CODE
def F(a,b):
q=0
w=0
i=0
u=0
while q<5 and w<5:
if random.random()<a:
i=1
u=u+1
else:
i=0
u=u+1
if random.random()>b:
u=u+1
if i==1:
if u%2==1:
w=w+1
else:
q=q+1
else:
u=u+1
if q<5:
return 0
if w<5:
return 1