Lab 3: The Game of Pig
Objectives
- Translate UML class diagrams into source code
- Construct software which uses class inheritance
- Employ method Overriding in the development of software
- Use the super keyword to execute constructors in a superclass
- Use the
java.util.ArrayList
collection class to hold class data
Resources
- Accept the GitHub Classroom assignment invitation in Canvas and then, in IntelliJ, create a new project from Version Control using the repository URL.
Introduction
In this assigment you will make a simple console implementation of the traditional dice jeopardy game Pig. Your implementation will allow for both human and AI ("bot") players.
The Game of Pig
Pig is a traditional dice jeopardy game. Players take turns, starting with a randomly chosen player. On their turn a player rolls a single 6-sided die 1 or more times. After each roll, the player has a choice:
- hold — Stop rolling and add the total of all numbers rolled this turn to their score, or
- roll — Roll the die again. If the player rolls a 1, their turn ends and they score 0 for the turn. Points scored on previous turns are preserved.
A player's turn ends when they roll a 1 or choose to hold. The first player to reach 100 points is the winner.
Software Design
You implementation should match the UML diagram below. The Pig
class is
included in the repository, but you will need to write the other classes yourself.
You will also notice that there is a Die
class for this game as well. Your
Die
class implementation must adhere to the design specified in this UML diagram.
All of the classes should be located in a package whose name matches your MSOE username.
The Player
s class hierarchy is used to specialize different types of players. While
the game treats all players equally, there are some differences.
- Human players — have names and decide whether to hold or not based on user input.
- AI players — are named "Bot #0", "Bot #1", etc... These names should be automatically generated by your program. AI players make the decision to hold (or not) according to an algorithm.
- Dumb AI players — have a 50% chance of holding (and a 50% chance of rolling again).
- Threshold AI players — have a threshold. If their score for the turn has reached or exceeded this threshold they hold, otherwise they roll again.
If you have any questions about what a method should do, ask your instructor.
Sample Run
Acknowledgment
This laboratory assignment was developed by Dr. William Retert and the CS1021 instructors.