The goal of this assignment is to give you more experience creating a class and writing code in C#.

You will create a baseball game simulator program. The program should allow the user to simulate the entire game all at once or play the game simulating half an inning at a time. There are 9 innings in a game of baseball. Each inning, both teams will take turns at bat and try to score as many runs as possible. The game should simulate a half inning by allowing the team at bat to score as many runs as possible until they earn 3 outs. The program needs to generate a random number to determine the outcome of each player's at bat. For example, you could simply randomly generate a number between 0 and 4 where 0 to indicates an out, 1 indicates a single base hit, 2 indicates a double (player reaches 2nd base), 3 indicates a triple (player reaches 3rd base), and 4 to indicate a home run. However, this would cause a large score since a homerun will occur 1 in 5 times. The best implementation would be to assign better chances of getting outs and base hits, and lesser chances of getting triples and home runs. You will need to devise a way to accomplish this. Hint: you need to use a random range of values (1 - 100) instead of using 5 values (0 - 5).

This program requires keeping track of several variables like the number of the number of outs, what bases are occupied, the team that is currently at bat, and a number of other elements for each half of inning. The key is to keep track of certain elements for the entire game, and others for just the half inning.

The challenging part is devising a way of move the players around the bases as the half inning is played. For example, a player at first base requires 3 moves to score a run: moving from first base to second base, second base to third base, and third base to home. This must be done using an Array. You cannot use if statements to determine how players will move. Otherwise, you would have somewhere in the vicinity of 44 number of if statements, and this wouldn't be practical, nor would it be good programming. Hint: use an array to represent the bases, store values in the array to indicate whether a bases is occupied by a player or not, and shift values in the array to simulate moving the players around the bases. This is the best solution to this problem.

The program should display the necessary information for each of the 4 innings as the game is played. You need to display the number of runs scored for the inning by both teams. When the game is over, all 9 innings should be displayed as being played with the number of runs scored for each team.

You need a BaseballSimulator class that will handle simulating one half of an inning (one team's opportunity to score runs before getting 3 outs). You can write the class to simulate an entire inning at a time, but I will leave that to you. This class needs at least one method to simulate either a half of an inning (which you can call 8 times to run the entire 4 innings) or an entire inning, it also needs some way of getting the runs scored for the half inning or entire inning, so the program that uses this class can display the runs scored.

1st 2nd 3rd 4th 5th 6th 7th 8th 9th Final
Phillies 0 2 1 0 0 1 0 2 0 6
Braves 0 0 0 1 0 0 0 1 0 2

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.