hi,
that's a nice project :)
just a simple comment of one of the functions though. In the gameOver function you're using a and c as parameters but inside of the function you're using a and b so it's probably gonna raise an exception that b is not defined. Better change it to c :) like this
def gameOver( a, c ):
# a and c are scores for players in a Table Tennix game
# Returns true if game is over, false otherwise
# return a == 11 or b == 11 and ((a - b) > 2 ) or ((a - b) < -2) becomes
return a == 1 or c == 11 and ( ( a - c ) > 2 ) or ( ( a - c ) < -1 )
an alternative would be just to change the parameter from c to b :)
as for your question as I recall a serve changes every 5 times right ? So what I would do is to have a counter in the simOneGame function that counts the number of serves. When the counter becomes 5 change the serving player. Here's what I mean:
def changeServing( s ):
if s == "A":
return "B"
else:
return "A"
def simOneGame(probA, probB):
""" Simulates a single game of Table Tennis between two players whose
abilities are represented by the probability of winning a serve.
Returns final scores for A and B """
serving = "A"
serveCount = 0
scoreA = 0
scoreB = 0
while not gameOver(scoreA, scoreB):
if servingCount == 5:
servingCount = 0
serving = changeServing( serving )
if serving == "A":
if random() < probA:
scoreA = scoreA + 1
else:
serving = "B"
else:
if random() < probB:
scoreB = scoreB + 1
else:
serving = "A"
servingCount += 1
return scoreA, scoreB
Of course this only works if you represent the serving with 'A' and 'B' otherwise you'll need to configure the changeServing function
hope this gives you some ideas :)