CSC 221: Computer Programming I
Fall 2004
HW4: Repetition and Simulation
For this assignment, you will modify the VolleyBallSimulator class and perform
numerous experiments using the simulation.
- Download the files VolleyBallSimulator.java and Die.java and build a working project. If you specify equal
rankings, are the scores of games relatively close? Should they be? Explain your answer
and provide the scores for several games to support it.
- As it is currently written, the winningPercentage method simulates multiple
games by repeatedly calling playGame. Unfortunately, this means that all of the
individual points in a game are displayed (by playGame), cluttering up the screen
and greatly slowing down the simulation. Make the following modifications to the class so
that the winningPercentage method can turn off output and so speed up the
simulation.
- Modify the VolleyBallSimulator class so
that it has another field, a boolean value named SHOW_POINTS, which initially is
true.
- The playGame method should be modified to check the value of this field --
if it is true, then the results of each rally should be displayed as before. If this
field
is false, however, then playGame should output nothing.
- Finally, modify the
winningPercentage method so that it sets the field to false before performing the
simulations, and then resets it to true when done.
- Assuming team 1 has a ranking of 50 and team 2 has a ranking of 55 (10% better),
perform three different sets of simulations for each of the following game lengths.
Report
the winning percentages of team 1 in the table below:
| SIMULATION 1 | SIMULATION 2 | SIMULATION 3
|
---|
1,000 games to 25 | | |
|
10,000 games to 25 | | |
|
100,000 games to 25 | | |
|
1,000 games to 30 | | |
|
10,000 games to 30 | | |
|
100,000 games to 30 | | |
|
- Does the consistency of the results improve when the number of games simulated
increases? That is, are the three percentages obtained from 10,000 games closer together
than the three percentages obtained from 1,000 games? Likewise, are the percentages
obtained from 100,000 games closer together than those obtained from 10,000 games? Should
they be? Explain.
- Are the winning percentages affected by the game length? That is, if the game is
longer, does this positively or negatively affect the chances of team 1 winning? If your
data suggests this, run several more simulations with different game lengths to confirm
the
pattern. Would this affect (if any) be more pronounced if the teams were less evenly
matched, say
50 vs. 80?
- Next, we want to compare the two different scoring schemes, rally and sideout scoring. A
simple approach would be to define another method, named playGameSideoutScoring, which
simulates a game using the sideout scoring system. This new method would be almost identical to
the existing playGame method that uses rally scoring, except that it would keep track of
who is serving and award a point only if the server wins the rally. In software development,
however, duplicating large blocks of code can lead to bad consequences. If any part of the
simulation were to change, then it would have to consistently change in both methods. A better
solution is to have a single method that works for either scoring scheme.
- Modify the playGame method to have an additional boolean parameter named
sideout. If this parameter is true, then the game simulation should use sideout
scoring. Otherwise, it should use rally scoring. Make this modified method private, so
that it can't be called directly by the user. To balance out the fact that sideout scoring gives
a slight advantage to the team who serves first, have the initial serve randomly assigned to one
of the teams.
- Define the following method, which calls the playGame method to simulate a game using
rally scoring.
/**
* Simulates an entire game using the rally scoring system.
* @param winningPoints the number of points needed to win the game (winningPoints > 0)
* @return the winner of the game (either "team 1" or "team 2")
*/
public String playGameRallyScoring(int winningPoints)
{
return playGame(winningPoints, false);
}
- Similarly, define a method playGameSideoutScoring that simulates a game using sideout
scoring.
- Finally, modify the winningPercentage method so that it performs repeated experiments
using both scoring schemes and displays both winning percentages. There should be an additional
parameter, allowing the user to specify different game lengths for each of the scoring schemes.
For example, the output of the method should look like:
Out of 10000 games, team 1 (50-55) won:
36.58% using rally scoring to 25
33.09% using sideout scoring to 30
- Assuming team 1 has a ranking of 50 and team 2 has a ranking of 60 (20% better),
perform three different sets of simulations for each of the following game lengths.
Report
the winning percentages of team 1 using both rally and sideout scoring in the table below:
| SIMULATION 1 (rally/sideout) | SIMULATION 2 (rally/sideout) | SIMULATION
3 (rally/sideout)
|
---|
1,000 games to 25 | | |
|
10,000 games to 25 | | |
|
100,000 games to 25 | | |
|
1,000 games to 30 | | |
|
10,000 games to 30 | | |
|
100,000 games to 30 | | |
|
- As we saw in class, rally scoring accentuates differences in talent. That is, if team 1 is
10% better than team 2, the likelihood of them winning a game is actually much more than 10%
better than for team 2. Which of the two scoring schemes accentuates differences more? Provide
statistics to justify your claim.
- Suppose you were a member of the committee deciding on a switch from sideout to rally scoring.
Recall that women's college volleyball previously used sideout scoring, with games played to 15.
Perform experiments to determine the equivalent game length for rally scoring that would preserve
competitive balance. That is, the winning percentage of team 1 using rally scoring should be
roughly the same sa the winning percentage using sideout scoring to 15. This relationship should
hold for a wide range of team strengths. Provide statistics to justify your answer.