Tuesday, July 28, 2009

I am trying to make a poker game in C++,How do you make a check for a pair in a players hand?

this is a peice of my code,


string general[52] = {"Ah","2h","3h","4h","5h","6h","7h","8h"...


"As","2s","3s","4s","5s","6s","7s","8s",...











int generalnumber[]={1,2,3,4,5,6,7,8,9,10,11...


31,32,33,34,35,36,37,38,39,40,41,42,43,4... //shuffled array Numbers corespond to cards in the deck Example: 1-13 is Ace of hearts to King of hearts and 14-26 Ace- King of diamonds and so on





Player 1 is an array that contains 5 elements for 5 cards but i am stuck on checked for a pair, within those 5 elements?


Thanks

I am trying to make a poker game in C++,How do you make a check for a pair in a players hand?
I won't write your homework for you, but I'll start you down the right path with some psuedo-code :)





You know Aces are 1, 14, 27, 30 - right?


And Deuces are 2, 15, 28, 31 - right?


So, each card is X, X+13, X+26, X+39





Using that, write one loop that goes through cards 1-4 (call the counter i)


inside that loop go through cards i+1 thru 5.


Do a modulo of 13 on each card (modulo tells you the remainder when divided by 13) That will tell you the card value. then see if one card has the same modulo as the first.





loop 1 thru 4 as i


int curCardVal = myhand[i] % 13


loop i+1 thru 5 as e


int nextCardVal = myhand[e] % 13


if nextCardVal = curCardVal


return pair


endLoop


endLoop





And really, a pair is the last thing you should check for simplicity. Check to make sure there isn't 4 of a kind or 3 of a kind first. That way you dont' accidentally identify 3 of a kind as a pair.

bouquet

No comments:

Post a Comment