|
-
October 19th, 2009, 03:17 AM
#3
Re: My GoFish Program
 Originally Posted by exiledgolem
Seems like there is a bug in it, and I can't really find out where. I'm not even sure if my algorithms are the best way of going about things but any help would be awesome.
It seems like my bug might have to deal with my checking for points algorithm... when I ask for input of a set that has already been made.. it's a longshot for a guess but it's a start..
Hi exiledgolem,
I looked at your code. Very nice, and well documented. I have to agree with Paul, some of those things in there could be heavily simplified. In particular, you have a heavy use of "magic numbers".
I would recommend you create a "card" struct, just for the heck of management, that can transform a card index into a value and a suit, like this:
PHP Code:
struct card
{
card(int intputIndex) : value(intputIndex%13), suit(intputIndex/13)
{}
card(int value, int suit) : value(value), suit(suit)
{}
const int value;
const int suit;
}
This way, you can understand your own code easier, by writing:
Code:
myCards[i]==card(9,3)
You know you are checking against the 9 of clubs.
You could make this even better by using an enum for your suits.
And with the single it constructor, you can still generate an entire deck by counting from 0 to 51 (although you could also be counting 4 times from 0 to twelve...)
Here is what I don't like about your program interface:
When the computer tells me that I have card "42" in my hand. What is that?
When the computer makes me write 4 when I want to check for a 5. Make the indexes match.
Here is what I don't like about your implementation:
You are using vectors, yet they always have a size of 52. In my opinion, you should be removing cards when they aren't there, rather than setting them to 0. This would also allow you to ditch the global "index" and "taken". Simply use pop_back for a new card, and check empty() to know if the game is over.
I know people say removing things from a vector is expensive, but not when it is from the back (as should be the case for the main deck). As for player hands, given the size, I don't really think you care.
I don't think CPlayer should be taking the one keeping track of who's turn it is. That is not its job.
Here is what is wrong about the program, simply by running it:
You never "go fish". You forgot to make the user draw a card if he fails to take one from the opponent. You never call CPlayer::Pickup.
Your opponent never plays. You never set your (or his) turn, except at construction time...
Other than that, not much. Please come back if yo are having more problems.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|