Go fish game help

Posted 15 November 2010 - 12:18 PM

I'm trying to write a Go Fish game in C++. I'm not a compsci major, I don't have much programming experience at all. The program involves simulated the go fish card game. I need major help with my shuffle function and the passing of cards between player's hands which are represented as arrays. We started arrays ~2 weeks ago so 4 classes maybe, and I don't have much experience with them. If anyone could take a look at my program and functions so far and give me some pointers it would be much appreciated. Thanks much.

Re: Go fish game help

You're trying to swap ocean[i] with ocean[n] but you're not retaining ocean[i] before you overwrite it. Use a temporary variable to hold it, then after copying ocean[n] to ocean[i] replace ocean[n] with your temporary variable.

Oh, and notice how I've remove the unnecessary white space. Too much is as bad as too little!

Re: Go fish game help

Posted 15 November 2010 - 12:41 PM

I'm not really sure if I understand. I'm trying to shuffle the deck by generating a random number to randomize the order of my deck array (ocean). So you're saying I should first put the ordered deck into a temporary value, then switch in the randomized numbers, and then put the ordered deck back in?

Re: Go fish game help

Posted 15 November 2010 - 12:55 PM

Imagine you have two cards on a table and you want to swap their positions, but you can only pick up one at a time. How would you do it? It seems to me that you would need a third, temporary position to put the first card so that you can move the second into the first card's original position. Then you could move the first card into the second card's original position.

One more thing:
You are only setting the random number "n" one time. I'd move that into the loop.

Re: Go fish game help

Posted 15 November 2010 - 12:57 PM

Ok that makes sense. Thanks a lot. Do my other functions look alright? They are supposed to draw cards from the deck, take cards from players hands, and check hands to see if there are any sets(4 of a kind) in the hands.

Re: Go fish game help

Re: Go fish game help

Posted 15 November 2010 - 02:54 PM

Ok I got the shuffle function working fine. The size of the deck is 32 for this program. We're using a shortened deck (only the numerical card values) to simplify the game. My problem right now is all the transactions of cards between arrays. Since I'm not that experienced with arrays I'm not really sure how you take one entry from one array and give it to another.

Re: Go fish game help

Posted 15 November 2010 - 03:35 PM

Arrays are passed by reference.
What baavgai was saying is that you should do something like:

#define DECK_SIZE 32
or

const int DECK_SIZE = 52;

So that you can use DECK_SIZE in your code and all you need to do is change the definition in one place to change it everywhere in the code. In addition, looking at DECK_SIZE is easier to understand than some seemingly random number. That makes editing much easier.

If you've got it working, post what you have along with a description of where you're stuck.

Re: Go fish game help

Re: Go fish game help

Posted 15 November 2010 - 03:58 PM

radicaledward, on 16 November 2010 - 07:48 AM, said:

Sorry for the formatting :x

Don't be sorry, be better.
The code goes between the code tags. Like this
Stop putting the opening tag and closing tag at the start of the code.
One goes before the code. One goes after the code.
Not a highly challenging concept really. Give it a try.
Make use of the "Preview" button to see if you got it right before posting.