Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need someones help! Write a C++ program that plays the game of “Go Fish”. Your

ID: 3768562 • Letter: I

Question

I need someones help!

Write a C++ program that plays the game of “Go Fish”. Your code must contain Game class, Deck Class, Player class, and Hand class. You must contain AI in your code

Put them into separate files such as;

main.cpp

Player.cpp Player.h

Game.cpp Game.h

Deck.cpp Deck.h

Hand.cpp Hand.h

There are many variations of Go Fish, but we are going to play with the following rules:
Players: 2 – 7
Supplies: 1 Deck of cards (52 total)
Objective: Collect as many groups of 4 cards of the same rank/value, and discard the groups from your hand, until you do not have any cards left. The first player to discard all of his/her cards wins!!! Playing: Start by dealing 7 cards to each player. Each player takes turns asking a specific player for a card of some rank. The player asked either has to give all of his/her cards of that rank and draw that many new cards from the top of the remaining cards or tell the player to “Go Fish” (pick up one card from the top of the remaining cards) because he/she isn’t holding any cards of that rank. This continues until a player discards all of his/her cards from collecting groups of 4 of the same rank.

What data will you have? There is the individual card, which has a suit (spade, heart, club, or diamond) and a rank (Ace, 2-10, Jack, Queen, or King). As there are no functions for a card you will use a struct:

struct card

{

string suit;

string rank;

};

There will be a Game class. This class has-a Deck (of cards) and has-a number (2-7) of Players. Each Players has-a Hand of cards. Each Player can give card(s) or receive cards. The player must also “lay down” any sets of 4 in its Hand. If its Hand is empty then that Player wins and the game is over!

How are these classes/structs used? A Game must shuffle and then deal 7 cards to each Player. Whenever a Player must draw 1 or more cards the Game must “deal” them to that player. Does the game do anything else?

A Deck has 52 cards: consisting of 4 suits for each 13 ranks. A deck of cards has activities associated with it. We can shuffle and deal the cards by rank. We deal cards by randomizing their order. To shuffle you will randomly put the cards into a stack. You will implement your own stack (using your code from previous projects is acceptable). You will NOT use a stack container from the STL or

other library. To deal you will take the top card and give it to each player in turn.

A Player receives the cards from the Game or another Player. New cards must be placed in their Hand. The player must lay down any sets of 4 in its hand. The Player also requests cards from another player. They either receive the card(s) requested, or they go fish and draw another card.

Does the Hand do anything other than hold the cards? If no then it should be a struct. If yes, it should be a class with the necessary functions. You should use an array or a vector to hold the cards. You will sort them by rank. You will need a function to determine what rank to ask for. Should you put that function in the Hand, or the Player, or some other class?

Where do you put the go_fish operation? Remember it must request cards of a player. If the player has cards of the requested rank she must hand them all over, AND draw that maney cards into her hand. The player making the request puts the cards into their hand. If that makes four of a kind then they must be laid down. If she does not have any cards of that rank the requesting player must go fish and draw a new card into his hand. All of this must be somewhere in your design, but not necessarily in one function.

You must ensure that all classes have the data and functions required by your analysis. The only stipulation is that you have to keep functions under 20 lines of code.

AI: You will have a queue that will keep a record of all requests made. The queue will have maximum length of twice the number of players in the current game. You will implement your own queue (using your code from previous projects is acceptable). You will NOT use a queue container from the STL or other library. Unlike a normal queue this one has a set maximum size, twice the number of players. If you add an item to the back that exceeds the size it automatically removes the front item. Also unlike a normal queue you must be able to iterate through the nodes to look at the previous requests.

You will need a struct that indicates the Player and what they asked for. Part of the “strategy” in playing Go Fish is remembering who asked for what. You can determine how far back they can “remember”. Notice that Reptiles have a different problem. If there are 4 players they do not “remember” the last 4 plays. They have a sliding window that is always N plays behind.

You must have one class per source file. You must have your class definitions in a .h file and your implemented classes in .cpp files. Place the structrs where it makes sense. You must also have your main function in a play_game.cpp file, separated from the class implementations. Create a Makefile for you project.

create the Game class and object (10%)

create the Deck class and objects, using the card struct (10%)

create the Player class and object (10%)

create the Hand class and object (10%)

your program correctly plays a game of Go Fish, with or without a human player (10%)

Explanation / Answer

#include 002 #include 003 #include 004 005 using namespace std; 006 007 void deckShuff(ocean[]){ // shuffles the deck 008       009       010     int position = 0; 011     int i = 0; 012     int n = 1 + rand() % 32; 013     while (i < 31){ 014         ocean[i] = ocean[n]; 015         i = i +1; 016     } 017 018 019 } 020 021 void drawCard( const int ocean[31], int& position, const int[]){ // simulates the drawing of a card from the deck 022     playerHand[] = playerHand[] + ocean[position] 023     ocean[31] = ocean[31] - ocean[position]; 024     position = position +1; 025 026 027       028 029 } 030 031 int ocean[35] = {2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9}; // arrays for values 032 int playerHand[20]; 033 int computerHand[20]; 034 int position = 0; 035 036 037 038 void checkcards(const int[], int rank, int size) { // checks hand for how many of a specific type of card 039     int i = 0; 040     int rankcount = 0; 041     while (i