![]() |
|
#1
|
|||
|
|||
wiriting a go-fish program?Part II: Programming
For this assignment, your job is to create a program that plays the children's card game "Go Fish". Name your program fish.py. The Rules There are many variations of Go Fish, probably one for every child that's ever played it. We will play a two-player version of Fish as follows: 1. A regular deck of 52 cards is used. The cards are every combination of 13 “ranks” (two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace) and 4 “suits” (spades, clubs, diamonds, hearts). 2. The deck is shuffled (put into a random order) and seven are dealt (given) to each player. The rest of the cards form the “stock”. 3. Whenever a player has any pairs (two cards with the same rank) in their hand, they are discarded (placed on the table, out of the player's hand). 4. Every time a player drops a pair of cards, they get one point. 5. The players then alternate taking “turns”: 1. The player asks their opponent for all of their cards of a particular rank. (“Give me all of your 3s.”) 2. A player can only ask for a rank that is actually represented in their hand. For example, if the player has no 3s, they cannot ask for 3s. So, a player with an empty hand can't ask for cards (and skips to (e)). 3. The opponent must give the player all of their cards of the specified rank. 4. If the player received any cards from their opponent, the turn continues (ask for another card, (a)). 5. If the opponent didn't have any of the requested rank, the player “goes fish”. They pick up a card from the stock and their turn is over. If the card they just picked up formed a pair, they must drop it, but their turn is still over. 6. When all of the 52 cards have been discarded as pairs, the player with the most points is the winner. Implementing To help you along, a cards module has been provided. You'll have to download the cards.pyc file. Save this file in the same directory as your fish.py file and you should be able to import cards. You must use the Card object to represent the cards in the deck and player's hands. The deck and a player's hand should be a list of Card objects. There are several functions in the cards module that will help you complete the assignment; they are described in the module documentation. Several hints have been provided to help you find your way through this assignment. Output There is no general way to clear the screen in Python, but you don't want to leave Player 1's cards on the screen when Player 2 starts. The easiest way to do this is to scroll Player 1's turn off the screen. You can do this by printing a bunch of line breaks: print "\n" * 60 In sample runs, this will be represented with a row of dashes. (because you really don't want to scroll down through 60 blank lines, do you?) Here is a short sample of what the program should look like when it runs. This is the first turn of each player. Player 1's Turn Player 1: 0 Player 2: 2 Cards left in stock: 38 Your cards: 2C 4S 6C 7H 8S 9D QD Ask other player for [23456789TJQKA]: 6 "Do you have any 6s?" "Yes: 6D" Your cards: 2C 4S 7H 8S 9D QD Ask other player for [23456789TJQKA]: 3 "Do you have any 3s?" You don't have any 3s. Make another choice. Your cards: 2C 4S 7H 8S 9D QD Ask other player for [23456789TJQKA]: 2 "Do you have any 2s?" "Go fish." You picked up the six of spades. End of turn, press enter. ------------------------------------------------------------ Player 2's Turn Player 1: 1 Player 2: 2 Cards left in stock: 37 Your cards: 3H 9C Ask other player for [23456789TJQKA]: 9 "Do you have any 9s?" "Yes: 9D" Your cards: 3H Ask other player for [23456789TJQKA]: 3 "Do you have any 3s?" "Go fish." You picked up the five of hearts. End of turn, press enter. There is another page of sample runs that you can look at as well. When you play the game, it should look like the given examples (i.e. all the messages, prompts, etc. should be the same). I was wondering if anyone could help me out? Or offer some good advice of where to start! o.o |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pipeline freeze simulation | darklightred | C++ Forum | 6 | 27-Jul-2006 19:37 |
| How to read particular memory location ? | realnapster | C Programming Language | 10 | 10-May-2006 09:11 |
| creating a file in [c] | i hate c | C Programming Language | 15 | 21-Nov-2005 12:52 |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 12:04 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 07:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The