CS 132 – Project 3: Go Fish!

Due: Monday, October 31st by the start of class

 

 

Introduction

 

The game of “Go Fish!” is a simple card game often played by children. When two players play the game, 7 cards are initially dealt to each.  The goal of the game is to make the most collections of all 4 of the same value card (called a “book”.) The player opposite the dealer goes first. He or she looks at his or her cards, chooses one, and asks the dealer if he or she has any of that particular denomination. If the dealer does, the dealer must hand to the player all of the cards he or she has in that denomination. If not, the player is instructed to “Go Fish!” which means to grab the next card off the remaining cards in the deck. If the dealer did in fact have the requested card, or the player was lucky enough to pick up that exact denomination of card from the deck, the player keeps playing. Otherwise it becomes the dealer’s turn to request a card.

 

Once player or dealer collects a book of a particular value, he or she may remove the cards from his or her hand, and scores an additional point in the game. The game continues until there are no more cards in the deck or the player or dealer has no cards remaining in his or her hand. At the end of the game, the player who made the most books wins.

 

Project Description

 

This project is a friendly competition.  Your job is not to write the entire game of “Go Fish!,”  as I’ve done that for you. Your job is to come up with the intelligence behind the players.  You will write a function that evaluates your hand and then determines which card to ask for. I will take all of your submissions and combine them with my driver program, and pit you in a head-to-head battle against the code written by your classmates. The winner will receive a prize.

 

Design-by-contract

 

Since you will be combining your code with code you did not write, we must agree upon some common interface so that the parts will work when we put them together. We will use C’s facilities for multi-file development, as well as a new preprocessor directive to achieve this.

 

This agreement on how to interface the components together is referred to as Design-by-contract in Software Engineering.

 

The contract for this particular project is as follows:


 

#ifdef PLAYER

int player_turn(int player_cards[], int num_cards) {

      return jrmst106_turn(player_cards, num_cards);

}

#endif

#ifdef DEALER

int dealer_turn(int dealer_cards[], int num_cards) {

      return jrmst106_turn(dealer_cards, num_cards);

}

#endif

int jrmst106_turn(int cards[], int num_cards)

{

      //random opponent

      return cards[rand()%num_cards];

}

 

You must make a file named your_username.c The file shown above is jrmst106.c (all lowercase please.)  Inside of it you must implement two functions: player_turn and dealer_turn. When you submit your program, these functions should simply call a function your_username_turn that does the actual guessing. In this example, my program simply picks a card at random to ask for.  Both the player and the dealer must play the same! You will play against your classmates 3 times as the dealer and 3 times as the player to avoid any bias from who begins.

 

The driver program (which we will dissect in class) will then play the two opponents against each other until a winner is determined.

 

Development

 

In order for you to test your function, I am providing you with all of the driver code. Under your private/cs132 directory, make a directory called project3 and cd into it. There execute the following:

 

cp  ~jrmst106/public/cs132/project3.tar  .

tar  xvf  project3.tar

 

This will create 3 files: Makefile, gofish.c, and jrmst106.c

 

Type  make and then run the gofish program to see it in action.

 

You can then make a copy of jrmst106.c with your username as the filename. Make sure you update the Makefile to compile the new file.

 


Hints

 

 

Requirements

 

By the deadline you must submit a tarfile containing: