CMPS 134 Fall 2019
Prog. Assg. #6: Baseball Game
Increment #1 is due at 11:59pm Wednesday, Nov. 13
Increment #2 (completed version) is due at 11:59pm Friday, Nov. 15

Background

A baseball1 game is played by two teams, generically referred to as home and visitor.2 A game consists of a sequence of innings, numbered starting at one, each of which has two halves. The "required" number of innings (i.e., the number of innings that must be played to constitute a full game) is typically either six (e.g., in "Little League"), seven (high school), or nine (major leagues), but, hypothetically, it could be any natural number.

During the first (or "top") half of each inning, the visiting team bats (i.e., is on offense). During the second (or "bottom") half, the home team bats. For convenience, we identify each half-inning with the team who is batting and thus refer to them as the visitor half and the home half, respectively, of the inning.

During the playing of a half-inning, the batting team's goal is to score runs3 and the defending team's goal is to make outs. When the third out of a half-inning has been made, the game proceeds to the next half-inning (except in cases where the game has come to an end). The details involved in batting, scoring runs, and making outs are extensive but are not of concern to us. (We are "abstracting them away".)

Upon completion of the required number of innings, the team that has scored the greater number of runs is declared the winner.4 However, it's not quite as simple as that, so some qualification is needed. To make things concrete, assume that we are talking about a 9-inning game (i.e., one for which the required number of innings is nine).

From these rules we can infer the existence of several baseball scenarios that often occur, including:


Given

You are given the following "artifacts":

Example Execution

9
oorro
oroo
rooo
ooo
ooo
oq
Sample
Input
 
The figure to the left shows the contents of a file suitable for use as input to the BaseballGameClient program. The first line contains the intended duration of the game (i.e., the minimum number of innings to be played). Each subsequent line contains one or more o's and r's representing out made and run scored events, respectively. (We have made each line of the file describe the events occurring during a single half-inning, but that is not a requirement; rather, it is just a formatting convention to make the file's contents more readily understood by a human reader.)

The figure below shows the output generated by the BaseballGameClient when given that sample input data. For each event code provided as input, the program shows (an encoding of) the state of the game after that event has occurred. To illustrate how the state of a game is encoded, consider as an example

[4-2][V7,1:9]

This describes the state of a 9-inning game in which the home team is leading by a score of 4 runs to 2, with 1 out having been made in the Visitor's half of the 7th inning.

Enter duration of game in # innings:9
New 9-inning game... [0-0][V1,0:9]

Enter event code(s) (o/r/q):oorro
Recording an out ... [0-0][V1,1:9]
Recording an out ... [0-0][V1,2:9]
Recording a run ...  [0-1][V1,2:9]
Recording a run ...  [0-2][V1,2:9]
Recording an out ... [0-2][H1,0:9]

Enter event code(s) (o/r/q):oroo
Recording an out ... [0-2][H1,1:9]
Recording a run ...  [1-2][H1,1:9]
Recording an out ... [1-2][H1,2:9]
Recording an out ... [1-2][V2,0:9]

Enter event code(s) (o/r/q):rooo
Recording a run ...  [1-3][V2,0:9]
Recording an out ... [1-3][V2,1:9]
Recording an out ... [1-3][V2,2:9]
Recording an out ... [1-3][H2,0:9]

Enter event code(s) (o/r/q):ooo
Recording an out ... [1-3][H2,1:9]
Recording an out ... [1-3][H2,2:9]
Recording an out ... [1-3][V3,0:9]

Enter event code(s) (o/r/q):ooo
Recording an out ... [1-3][V3,1:9]
Recording an out ... [1-3][V3,2:9]
Recording an out ... [1-3][H3,0:9]

Enter event code(s) (o/r/q):oq
Recording an out ... [1-3][H3,1:9]
Quitting ...         [1-3][H3,1:9]

*** Game not over
Goodbye.

Assignment

You are to submit your work in two increments. For the first, the goal is to put into working order all the observer methods whose names include the word "inning" (possibly plural or capitalized). Of course, this means that any methods upon which those methods rely must also be put into working order. It also means that one or more instance variables may need to be introduced.

After completing the first increment, what should be left is to put into working order the methods that pertain to runs being scored and methods that determine whether a game is over (and, if so, who won). That is your task for the second increment.

There will be two distinct folders into which to submit your BaseballGame source code, one for each increment. The names of the folders will make obvious which increment each one refers to.

As usual, your source code should include comments that identify you, any persons with whom you collaborated, and any defects that you are aware of.


Footnotes

[1] The descriptions here also apply to the game of softball.

[2] Typically, games are played on a field that is considered to be one team's "home" field, because they play many of their games there and perhaps also practice there.

[3] Scoring a run in baseball is analogous to scoring a "point" in most other games.

[4] Except in unusual circumstances (that we will not address here), a baseball game cannot end in a tie/draw.

[5] There is no need for the home team to bat in its half of the 9th inning because whether or not it scores any additional runs will have no bearing upon the game's outcome.

[6] Such an ending to a game is known as a "walkoff". There is no need for the home team to continue batting, for the same reason as offered in the previous footnote.