CPSC 225 | Intermediate Programming | Spring 2025 |
The goal of project 1 is to review procedural programming (part A) and object-oriented programming (part B), and to dust the cobwebs off with regards to Java syntax and program construction.
Fixing problems is an important component of learning, and most assignments will have an opportunity for revise-and-resubmit. The resubmit deadline will be announced when the initial handin is handed back, and will generally allow a week or so for revision.
Revise-and-resubmit requires there to be something to revise and feedback to act on — it is not intended as a de facto extension. To be eligible for revise-and-resubmit, there must be some effort put into the assignment (a 3 or higher).
Late work is generally not accepted. If circumstances beyond your control prevent you from making any progress on an assignment before it is due, you are at significant risk of falling behind in the course. Come talk to me ASAP!
You may use the course materials (slides, examples) posted on the course webpage and the course Canvas site. If you get stuck on aspects of Java, remember that you can review chapters 2-4 in the textbook.
You are encouraged to come to office hours and Teaching Fellows for help with thinking through getting started, Java help, debugging help, or help with anything else you might be stuck on.
The use of generative AI (such as ChatGPT), homework help websites, or other resources (friends, YouTube, etc) as learning cheats is not permitted. "As a learning cheat" means generating, finding, copying, etc code that you incorporate directly or with only minor modifications into your solution. The most egregious version of this is generating the entire program, but the prohibition applies to even small sections of code as well.
Using other resources as learning aids is permitted, but you are strongly encouraged to utilize the course materials, office hours, and Teaching Fellows as your primary sources of help. "As a learning aid" is to understand concepts — e.g. getting examples of loops to understand how to write loops in general or the specific syntax for loops in Java, not their specific application to this program. ("An example of a program to play flip" is a solution, not an example, and is not a learning aid.)
To hand in your work:
Make sure all your Java files have been auto-formatted and saved, and that your name is in an @author tag at the beginning of each file.
Copy the entire ooflip project directory to your handin directory. Make sure that you end up with ooflip directly inside your handin directory, with the Java files themselves in a src folder inside ooflip. Don't introduce extra directories or leave some out!
Flip is a 2-player "strategic change-making game" published by Cheapass Games. You can find it, along with many other games, in the Game Preserve. (If you enjoy it, considering purchasing a copy.)
Each player starts with five dice. Roll the dice, and the player with the lowest total goes first. The players then alternate turns.
On each turn, the player either flips one of their own dice or plays one of their opponent's dice. However, players may not flip the same die twice without first playing one of the opponent's dice.
Flipping means to turn the die to the opposite side of what is showing; since the top and bottom numbers of 6-sided dice always sum to 7, this means that the new value of a flipped die is 7 minus the old value. (6 flips to 1, 5 flips to 2, 4 flips to 3, 3 flips to 4, etc.)
Playing means to put one of the opponent's dice into the middle of the table. They can then remove any number of dice whose total value does not exceed the value of the die played. For example, if a 6 is played, up to 5 points worth of dice can be removed from the middle.
The game continues until one player runs out of dice. The winner is the player with dice remaining, and the points scored is the sum of their dice.
Reset and continuing playing games until a player reaches 50 points.
Your task is to write a Java program to play flip as described above. Name your Eclipse project ooflip and the main program OOFlip.
This time you must use one of the provided object-oriented designs (posted on the schedule page). These are designs #1 and #2 in the posted "class designs for OO Flip" handout.
Your program should display sufficient output so that the players can follow and play the game. In particular, the current game state (player 1's dice, player 2's dice, the dice in the middle, and which dice are flippable or not) should be displayed at the beginning of each turn, the winner and the current point totals for both players should be displayed at the end of each game, and the overall winner should be congratulated when 50 points is reached.
Your program should also perform appropriate error-checking and enforce the game rules. For example, players shouldn't be able to pick a non-existent die to flip or play, and players may not flip an unflippable die or remove too many points' worth of dice from the middle.
Start with high level pseudocode — don't get tangled up at first with how you are going to keep track of the dice, but instead use language at the level of the classes identified in the class design and arrange that into the fundamental flow-of-control constructs (sequence of steps, choice between alternatives, repetition) needed to capture the program logic. (You should already have a good start on this from Flip.) When you start to work on code, you can focus on implementing classes first or the main program first (with placeholder bodies for the class methods) or a mix of the two — build up the main program incrementally, and implement class methods as you need them to support the main program.
Depending on which class design you use, either use an ArrayList of dice (see section 7.3 in the textbook if you aren't familiar with ArrayList) or the array-of-counts scheme from Flip for the collections of dice.