Software Development, Design Choices, Class Design, Recursion and Iteration, Testing, and Command-line Arguments 2011-2012 A Racquetball or Volleyball Simulation

Introduction

Materials on this Web site consider various solutions relating to the simulation of games of racquetball or volleyball. Overall, this simulation provides a convenient vehicle to address a wide range of issues related to

• software development,
• class design,
• algorithmic development,
• recursion and iteration,
• program testing (particularly for simulations), and
• command-line parameters.

Description of Racquetball and Volleyball

The following description of the games of racquetball and volleball is taken, largely verbatim, from the author's Classroom Issues article, cited in the reference section below.

Both racquetball and volleyball are played by two players or teams. (To simplify discussion, we consider a player as a team of one.) Scoring proceeds as follows:

```    The score starts at 0-0.
Team A starts serving.
When Team A wins a volley, A scores a point and is allowed to serve again.
When Team A loses a volley, A loses the serve, but no points are scored.
Team B starts serving.
When Team B wins a volley, B scores a point and is allowed to serve again.
When Team B loses a volley, B loses the serve, but no points are scored.
```

Altogether, a team only scores points while it serves and wins volleys. When a team loses a volley, it loses the serve, but no points are scored. In racquetball, the first team to reach 15 points wins; in volleyball, a team wins when it reaches 15 points, but it must win by at least two points. For example, if the score is 15-14, then the team with 15 points wins immediately in racquetball, but play must continue in volleyball until one team leads by two points.

Programming Simulation Problem

This section also closely follows the author's Classroom Issues article, cited in the references.

Let PrA be the probability that Team A wins a volley. To explore the likelihood that A will win a game, a program is to be developed to simulate 1000 games for each value of PrA with Team A serving first for each game; and PrA should take on successive probabilities 0.40, 0.41, 0.42, ..., 0.59, 0.60. As an example, the following listing illustrates the desired format for a possible program run.

```    Simulation of racquetball based on 1000 games
Must win by 2:  false

Probabilities         Percentage
for winning volley        of Wins
A       B            A        B

40%     60%           7%      93%
41%     59%          10%      90%
42%     58%          13%      87%
43%     57%          14%      86%
44%     56%          21%      79%
45%     55%          24%      76%
46%     54%          30%      70%
47%     53%          33%      67%
48%     52%          40%      60%
49%     51%          48%      52%
50%     50%          52%      48%
51%     49%          59%      41%
52%     48%          63%      37%
53%     47%          70%      30%
54%     46%          74%      26%
55%     45%          79%      21%
56%     44%          83%      17%
57%     43%          87%      13%
58%     42%          91%       9%
59%     41%          93%       7%
60%     40%          94%       6%
```

Organization of this Site

Since programs to simulate racquetball or volleyball touch upon many elements of software development, this Web site organizes materials into pieces. This main page states the basic problem, displays a sample output from a simulation, and provides links to other materials (e.g., readings, labs, and sample programs). Other pages focus upon specific parts of the software development process.

In particular, this Web site contains the following major sections:

Complete Programs

The following table identifies several complete simulation programs that illustrate various design choices.

Approach Game Flow Recursive/Iterative Program
Store game, simulation data in object Flow 1: Serve-by-serve Recursive Game1Recur.java
Store game, simulation data in object Flow 1: Serve-by-serve Iterative Game1Iter1.java
Store game, simulation data in object Flow 2: Repeat A serves then B serves until win;
no helper methods for playing game
Iterative Game1Iter2.java
Store game, simulation data in object Flow 2: Repeat A serves then B serves until win;
uses helper methods when playing game
Iterative Game1Iter2Alt.java
Store game, simulation data in static variables Flow 1: Serve-by-serve Recursive Game2Recur.java
Store game, simulation data in static variables Flow 1: Serve-by-serve
include Boolean variables to control tracing
Recursive Game3Recur.java
Store game, simulation data in static variables Flow 1: Serve-by-serve
use command-line arguments to specify game
Recursive Game4Recur.java

Reference and Acknowledgment

This Web site extends the author's Classroom Issues article, "A Racquetball or Volleyball Simulation", SIGCSE Bulletin inroads, Volume 20, Number 4, December 1997, pp. 22-23. Access to the archival article is available without charge by clicking through the article title at this page maintained by the author.