As a capstone to the first semester, in this project, you are going to complete a series of activities to create a small card game called GOPS (or "Goofspiel"). GOPS stands for "Game of Pure Strategy", and the game is named that way because two players can, in theory, compete on equal footing without any luck involved.
This lesson describes the card game rules - and the modifications we'll make to create a version in Python. You will then complete the game over a series of two guided activities. Finally, in the third (optional) Q&A activity, you can answer a series of questions about the design and implementation of your game.
Your answers in the third activity are not auto-graded by our system. Your teacher must assign a grade to your answers. This activity is optional - check with your teacher to see if you should complete the Q&A activity.
Students taking an AP Computer Science Principles class must submit a "Create Performance Task" to the College Board as part of their exam grade. This project demonstrates the scope and complexity of the type of program you must be able to create on your own (or in a small group) as part of the "Create Performance Task". You will need to write your own, creative program for this task. For more information, please see Chapter 21.
Your teacher may optionally ask you to complete this project in small teams of 2 or 3 students. Otherwise, simply complete each activity on your own.
GOPS - Overview
GOPS is normally played with two players and part of a standard 52-card deck of playing cards. The cards are initially distributed as follows:
All "spades" are given to player 1.
All "clubs" are given to player 2.
All "diamonds" are shuffled and placed face-down in the middle as a draw pile.
All "hearts" are set aside and are not used in the game.
Each suit (spades, clubs, diamonds) has 13 cards labeled Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King. The goal of the game is to capture as many of the diamonds as possible. Each diamond is worth the amount of points shown on the face (e.g. 2, 3, 4...). The Ace is worth 1 point (low card) and the Jack, Queen, and King are worth 11, 12, and 13 points.
The game is played in 13 rounds. At the beginning of each round, the top diamond card is taken from the shuffled draw pile and displayed face-up in the middle.
Starting GOPS configuration
Each player will then select one of the cards from their own hand (spade or club) as a secret "bid". Once both players have selected a card, they are flipped over, and the player that has selected the highest card wins the diamond card(s) in the middle.
GOPS game round
If both players have secretly made the same bid, then the card in the middle remains as part of the prize for the next round
After 13 rounds, all diamond cards are gone and have been captured by either player 1 or player 2. The total point values of all diamonds are added together for each player to determine the winner. The example below shows a simplified calculation of player scores using only the diamonds 2 through 10.
Calculating score
Why is this a game of pure strategy? Both players have the same starting cards to use as bids, and each player can independently select how much to "bid" based on the value of the card(s) in the middle and the remaining cards in their hands. Two human players will each make any desired strategic bid based on what their opponent has already bid, the value of the cards in the middle, and their own remaining cards.
GOPS - Our Python Version
We are going to modify the GOPS rules slightly to make it easier to program in Python and easier to finish a complete game quickly.
If using our online coding engine, every program run is limited to 60 seconds or less. If you are running Python on your local computer or using some other external development environment, then you do not have the same run-time limitation.
In our version, we are going to remove all "face" cards from the deck, so there will be no Jack, Queen, King, or Ace. That means all 9 remaining cards are worth exactly the point value shown (2 through 10). The entire game will be complete in 9 rounds instead of 13.
Additionally, our Python game will have one human player and one computer player. The computer player will select a card based on an algorithm that you create. The human player will have no knowledge of what the computer will bid, and the computer algorithm will not know anything about the human's bid.
When the program starts, the user will enter a random seed to initialize the random number generator. The random number generator is only to shuffle the deck of face-down diamonds before play starts, and it may also be used by the computer algorithm to select a card for player 2 in each round.
Enter random seed: 1
Next, the top diamond card is taken from the draw pile and shown face-up in the middle. In this example, the 4 card is shown first. The list of spades remaining in the human player 1 hand is shown, and the human player will make a selection from that list. Below, the human player bids a "5" to capture the middle "4" card.
Enter random seed: 1
Middle card(s): [4]
Player 1 available: [2, 3, 4, 5, 6, 7, 8, 9, 10]
Enter player 1 bid: 5
Next, the computer algorithm will make a selection from the list of clubs remaining for player 2.
Enter random seed: 1
Middle card(s): [4]
Player 1 available: [2, 3, 4, 5, 6, 7, 8, 9, 10]
Enter player 1 bid: 5
Player 2 bid: 3
To end the round, the player with the highest bid (player 1 in this example) gets all of the middle card(s) added to that player's capture list. The next line shows which player wins the bid and a summary of all captured diamonds for that player. So far, player 1 has just captured the 4 card.
Enter random seed: 1
Middle card(s): [4]
Player 1 available: [2, 3, 4, 5, 6, 7, 8, 9, 10]
Enter player 1 bid: 5
Player 2 bid: 3
Player 1 wins bid, has captured [4]
The next round begins with the next diamond shown taken from the draw pile and placed in the middle. The human and computer players continue bidding in each round. Captured diamonds are added to each player's list. Here is a complete program run showing all 9 rounds.
Enter random seed: 1
Middle card(s): [4]
Player 1 available: [2, 3, 4, 5, 6, 7, 8, 9, 10]
Enter player 1 bid: 4
Player 2 bid: 3
Player 1 wins bid, has captured [4]
Middle card(s): [5]
Player 1 available: [2, 3, 5, 6, 7, 8, 9, 10]
Enter player 1 bid: 3
Player 2 bid: 10
Player 2 wins bid, has captured [5]
Middle card(s): [6]
Player 1 available: [2, 5, 6, 7, 8, 9, 10]
Enter player 1 bid: 2
Player 2 bid: 2
Tie bid - middle card remains
Middle card(s): [6, 10]
Player 1 available: [5, 6, 7, 8, 9, 10]
Enter player 1 bid: 10
Player 2 bid: 7
Player 1 wins bid, has captured [4, 6, 10]
Middle card(s): [9]
Player 1 available: [5, 6, 7, 8, 9]
Enter player 1 bid: 9
Player 2 bid: 8
Player 1 wins bid, has captured [4, 6, 10, 9]
Middle card(s): [2]
Player 1 available: [5, 6, 7, 8]
Enter player 1 bid: 5
Player 2 bid: 4
Player 1 wins bid, has captured [4, 6, 10, 9, 2]
Middle card(s): [8]
Player 1 available: [6, 7, 8]
Enter player 1 bid: 6
Player 2 bid: 9
Player 2 wins bid, has captured [5, 8]
Middle card(s): [7]
Player 1 available: [7, 8]
Enter player 1 bid: 8
Player 2 bid: 6
Player 1 wins bid, has captured [4, 6, 10, 9, 2, 7]
Middle card(s): [3]
Player 1 available: [7]
Enter player 1 bid: 7
Player 2 bid: 5
Player 1 wins bid, has captured [4, 6, 10, 9, 2, 7, 3]
===GAME OVER===
Player 1 captured: [4, 6, 10, 9, 2, 7, 3]
Player 2 captured: [5, 8]
Player 1 scored 41, Player 2 scored 13
PLAYER 1 WINNER
At the end of the game, you see a "===GAME OVER===" message. The diamonds captured by each player are shown, along with the calculated score for each player and the overall winner. In this example, player 1 has captured the 4, 6, 10, 9, 2, 7, and 3 cards, which total 41 points. Player 2 has only captured the 5 and 8 for 13 total points, so player 1 is the winner.
Take careful note of this sequence:
Middle card(s): [6]
Player 1 available: [2, 5, 6, 7, 8, 9, 10]
Enter player 1 bid: 2
Player 2 available: [2, 4, 5, 6, 7, 8, 9]
Player 2 bid: 2
Tie bid - middle card remains
Middle card(s): [6, 10]
In this round, both players bid "2" for the middle "6" card, so the result is a tie. The 6 is left in the middle and the next round draw (a "10") is added to that middle stack. The winner of the next round will get both the "6" and "10" cards - a valuable prize! Each time the bids are the same, whatever is in the middle remains as part of the prize for the next round.
Progression and File Management
Be sure to complete the two activities in order. You will begin the first activity with some starting code and will complete about half the project. When starting the second activity, you will need to copy in your successfully completed code from the first activity to proceed.
This approach demonstrates how you can take a larger project and break it down into more manageable pieces. When your smaller pieces are fully tested, you can confidently combine them into a larger project and won't have to track down as many errors over the larger code base.
Python Skills
This project will not introduce any new Python skills. It will give you a chance to practice and re-enforce the things you have already learned, including:
Working with data
Boolean logic and making decisions
Getting and validating user input
Looping
Using lists
Writing functions
Using the random library
Debugging and testing code
Be sure to refer back to earlier chapters that demonstrate these concepts, if needed!
3 answers
2. How does each round of GOPS get played? What begins the round, what two things happen next, and how are the results determined?
3. When does the GOPS game end? How is a winner determined?
4. What rules modifications are made for our Python GOPS game?
5. What happens if two players each make the same bid for card(s) in the middle?
6. In what order should you complete the chapter activities?
2. Each round of GOPS starts with the top diamond card from the draw pile being shown face-up in the middle. Players then select a card from their hand as a secret bid. Once both players reveal their bids, the player with the highest bid wins the diamond cards in the middle.
3. The GOPS game ends after 9 rounds when all diamond cards have been captured. The winner is determined by totaling the points of the captured diamond cards for each player.
4. In our Python version of GOPS, we only use the cards 2 through 10, and the game is played in 9 rounds. Additionally, we have one human player and one computer player.
5. If both players make the same bid for the card(s) in the middle, the card(s) remain as part of the prize for the next round, creating a potential tie scenario.
6. The chapter activities should be completed in order, starting with the first activity, where you will begin with some starting code and complete about half of the project. Then, you will copy your completed code into the second activity to finish the project.