The program handin21 will only submit files in the cs21/homework/10 directory.
Your programs are graded on both correctness and style. Please review the comments regarding programming style on the main page
Some of the problems will have optional components that allow you to
further practice your skills in Python. Optional portions will not be
graded, but may be interesting for those wanting some extra challenges.
To start the game, the deck is shuffled and seven cards are dealt to each player. The rest of the deck is set aside as a draw pile. Players then take turns playing until the draw pile is empty and one player has no cards in his/her hand. A turn consists of the following steps. For simplicity, we refer to the players as Alice and Bob and describe the turn for Alice.
At the end of the game, both players total their books and the player with the most books wins. Note that with two players and thirteen books, there cannot be ties.
Your assignment is to write a few classes that will play the game Go Farm. The outline of your program will be similar to the Black Jack game we wrote in class. You should have Card, Deck, GoFarmPlayer, and GoFarmGame classes. You should reuse or extend the Card and Deck classes that we wrote in class.
Your program must have the following components:
Some sample output is shown below:
Welcome to the game Go Farm. Enter name of player 1: Alice Enter name of player 2: Bob Alice, your hand is: [one 6, one 7, one 10, two Jacks, one Queen, one King] You currently have 0 books and 7 cards Which rank do you want to ask for? 2 You do not have a card of this rank. Choose again Which rank do you want to ask for? acorn Acorn is not a valid rank. Choose again Which rank do you want to ask for? queen Got 1 Queen from Bob You get another turn Alice, your hand is: [one 6, one 7, one 10, two Jacks, two Queens, one King] You currently have 0 books and 8 cards Which rank do you want to ask for? queen Bob doesn't have that rank Looks like it is time to Go Farm! You drew the 6 of Clubs. ... SKIPPING a lot of turns ... Bob, your hand is: [one 2, two 3s, one 4, two 5s, two 8s, three 10s] You currently have 0 books and 11 cards Which rank do you want to ask for? 5 Alice doesn't have that rank Looks like it is time to Go Farm! You drew the 5 of Diamonds. You got want you wanted and get another turn. ...SKIP... Alice, your hand is: [two 6s, two 7s, two 9s, one 10, three Jacks, two Queens, three Kings, one Ace] You currently have 0 books and 16 cards Which rank do you want to ask for? 10 Got 3 10s from Bob You get another turn You formed a new book! Alice, your hand is: [two 6s, two 7s, two 9s, three Jacks, two Queens, three Kings, one Ace] You currently have 1 books and 15 cards Which rank do you want to ask for? ...SKIP... Alice, your hand is: [three 7s] You currently have 8 books and 3 cards Which rank do you want to ask for? 7 Got 1 7 from Bob You get another turn You formed a new book! You currently have 9 books and 0 cards Alice, your hand is: No cards in Hand You currently have 9 books and 0 cards You have no cards and must draw a card. You drew the 8 of Diamonds. Alice, your hand is: [one 8] Which rank do you want to ask for? 8 Got 3 8s from Bob You get another turn You formed a new book! You currently have 10 books and 0 cards No cards left. Game is over. Alice beat Bob 10 books to 3
[two 6s, two 7s, two 9s, three Jacks, two Queens, three Kings, one Ace]is much more compact than writing out all 15 cards with their suits. It is not mandatory that you follow this format, but you might find it to be a useful representation of a hand.
You can change into your homework 10 directory using the cd command
cd cs21/homework/10/
To run your game or other test code, type python game.py where game.py is the name of your game program. If you would like to stay in the python environment after running you game, you can type python -i game.py which will return you to a python prompt >>>. Here you can type additional python commands and test your code some more. To quit the python shell, press Ctrl-D.
You can still use IDLE to edit and save your work, but using python from the terminal will save you from a number of strange IDLE problems.