Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

You are to program to play fish against the computer. The rules of fish can be found on many internet sites. A sample explanation of

You are to program to play fish against the computer.

The rules of fish can be found on many internet sites. A sample explanation of the game as taken from Wikipedia is:

Five cards are dealt from a standard 52-card deck to each player, or seven cards if there are four or fewer players. The remaining cards are shared between the players, usually spread out in a disorderly pile referred to as the "ocean" or "pool".

The player whose turn it is to play asks another player for his or her cards of a particular face value. For example Alice may ask, "Bob, do you have any threes?" Alice must have at least one card of the rank she requested. Bob must hand over all cards of that rank if possible. If he has none, Bob tells Alice to "go fish" (or simply "fish"), and Alice draws a card from the pool and places it in her own hand. Then it is the next player's turn - unless the card Alice drew is the card she asked for, in which case she shows it to the other players, and she gets another turn. When any player at any time has all four cards of one face value, it forms a book, and the cards must be placed face up in front of that player.

Play proceeds to the left. When all sets of cards have been laid down in books, the game ends. The player with the most books wins. 

You may choose any logic/data structure you like for this program, but you must at least do the following:

  • You will display the "go fish" rules you are using for your program in a dialog box
  • You will use only one deck of cards, see below:
d12e86e2c3c2f3441514869384726ecf.png

Image transcription text

Example set of 52 playing cards; 13 of each suit clubs, diamonds, hearts, and spades Ace 2 3 4 5 6 7 8 9 10 Jack Queen King Clubs Diamonds Hearts
SpadesExample set of 52 playing cards; 13 of each suit clubs, diamonds, hearts, and spades Ace 2 3 4 5 6 7 8 9 10 Jack Queen King Clubs Diamonds
Hearts Spades


  • You are to load all cards into memory when your game begins.  (this has been done for you in the go_fish_game.java file).
  • You will then deal 7 cards one at a time alternating between the computer and the player. The go_fish_game.java program also has a method that randomly deals a card. You are NOT allowed to deal the same card more than once.  Therefore, you will have to keep track if the card has been dealt.  Remember that you will be using a random number generator to deal the cards.  If the card has been dealt already, you will have to generate another card.
  • While you are working on this program, you can display all cards the player and the computer have.  Once you get it all working, you will hide from view the cards in the computer hands.
  • After a game has been won, you are to print a final summary of how many books the user had and how many the computer had and who won.

 

 

Possible ideas of how to approach this problem:

  • You will need a data structure to keep track of the cards the computer has and a separate data structure for the player's hand. In that data structure, you will have to keep track of the count of each type of card the player and the computer have.
  • You will also need additional data structures to keep track of the number of books both the computer and the player have.  You should also keep track of what the book is, 4,5 6, ace, king, etc...
  • For the data structures, you could use arrays or linked lists.
     

Example set of 52 playing cards; 13 of each suit clubs, diamonds, hearts, and spades Ace 2 3 4 5 6 7 8 9 10 Jack Queen King Clubs Diamonds Hearts Spades #12 (DX

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

import javautil public class GoFishGame private static final int NUMCARDS 52 private static final in... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting Information Systems

Authors: Marshall B. Romney, Paul J. Steinbart

13th edition

133428532, 978-0133428537

More Books

Students explore these related Programming questions