Maggie3287
Squash
A game of squash is played by two people: player 1 and player 2. The game consists of a sequence of points. If player i serves and wins the point, then his/her score increases by 1 and he/she retains the serve (for i = 1 or 2). If player i serves and loses the point, then the serve is transferred to the other player and the scores stay the same.
The winner is the first person to get 9 points, unless the score reaches 8 all first. If the score reaches 8 all then play continues until one player is 2 points ahead of the other, in which case they are the winner.
The object of this assignment is to simulate a game of squash and estimate the probability that player 1 wins.
Define
a = P( player 1 wins a point | player 1 serves )
b = P( player 1 wins a point | player 2 serves )
x = number of points won by player 1
y = number of points won by player 2
z = 1 if player 1 has the serve
z = 2 if player 2 has the serve
Assume that player 1 serves first
Question 1
Write a function status which takes inputs x and y and returns one of the following text strings:
"unfinished" if the game has not yet finished;
"player 1 win" if player 1 has won the game;
"player 2 win" if player 2 has won the game;
"impossible" if x and y are impossible scores.
Assume that the inputs x and y are integers.
When you have written your function, load the function status.test available on the
course website, and execute the expression status.test(status).