Fall 2011

In class, we developed a series of Python functions for simulating the game of Pig and collecting statistics on game lengths (see control.pytxt for the code). For this assignment, you will develop similar functions for simulating volleyball games and collecting statistics on winning percentages.

Assume that the two teams in a volleyball game are each given a power ranking: an integer between 1 and 100. The higher the power ranking, the more likely that team is to win a particular point. For example, if team 1 and team 2 have identical power rankings, say 60 and 60, each is equally likely to win a given point. However, if team 1 has a power ranking of 80 and team 2 has a power ranking of 40, then team 1 is twice as likely to win a given point. The following Python function can be used to simulate a single point in a volleyball game.

- Define a Python function named
`playGame`that simulates a complete game of volleyball by calling`playPoint`repeatedly. The function has three inputs, the number of points required to win a game, the power ranking of team 1, and the power ranking of team2. It should*print*the score after each point and, at the end of the game,*return*the winning team number. For example:

- Once you have your
`playGame`function working correctly, comment out the print statement by placing a '#' character at the front of the line. Then define a second function named`playStats`that performs repeated game simulations and keeps track of the winning percentages of the teams. The function should have four inputs, the number of games to be played, the number of points required to win a game, and the power rankings of the two teams. It should then repeatedly call the`playGame`function and keep track of the number of wins by each team. At the end, it should*print*a message of the form "Team 1 won X % of the games", where X is the winning percentage of team 1.

- In our model, the power rankings provide a way of predicting which team will win a given point. A team with a 50% advantage in power rankings (e.g., 60 vs. 40) is 50% more likely to win a given point. However, this relative advantage may not hold the same over the course of an entire game. You are to conduct several experiments with different power rankings to determine how a relative advantage in points translates to a relative advantage in games.
For each simulation, assume 10,000 games are to be played, with each requiring 15 points to win.
team1/team2 rankings expected % of points

won by team 1actual % of games

won by team 150/50 50.0% 55/50 52.4% 60/50 54.5% 75/50 60.0% 80/40 66.7% 60/20 75.0% 80/20 80.0%

- Now, repeat your experiments, only with longer games. For each simulation, assume 10,000 games are to be played, with each requiring 25 points to win.
team1/team2 rankings expected % of points

won by team 1actual % of games

won by team 150/50 50.0% 55/50 52.4% 60/50 54.5% 75/50 60.0% 80/40 66.7% 60/20 75.0% 80/20 80.0%

*Note: this work must be entirely your own, with no outside assistance other than the instructor.*