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 flip project directory to your handin directory. Make sure that you end up with flip directly inside your handin directory, with the Java files themselves in a src folder inside flip. 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 flip and the main program Flip.
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 and their flippable status, but instead start with the level of language given in the game description above and arrange that into the fundamental flow-of-control constructs (sequence of steps, choice between alternatives, repetition) needed to capture the program logic. When you start to work on code, keep in mind using functions/subroutines to manage complexity — both as placeholders as you incrementally build up the program and to contain complex tasks in order to keep the overall logic of the main program simpler.
An important part of this program is keeping track of the dice and their status (flippable or not). A useful observation is that two dice showing the same value are interchangeable — all you need to keep track of is how many of each value a player has or are in the middle — e.g. player 1 might have one 1, two 3s, and one 6. Clever use of arrays can make this convenient. (Think about how this might work, then see section 3.8.3 in the textbook if you are stuck.) To keep track of flippable vs not flippable dice, consider having two arrays for each player — one keeping track of that player's flippable dice and one for the unflippable dice.