# Poker Coding

This topic is 4535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I hope this is the rightr forum i barely have any time and i want an answer when i get back(hopefully) im creating a poker game can anyone lead me or help me with coding the part where the game can read a straight hand 1,2,3,4,5 10,jack,queen,king,ace 3,6,5,4,2 queen,10,jack,ace,king know what i mean? thx

##### Share on other sites
cards should have a numerical value

1) sort hand by numerical value
2) iterate hand and see if each card is only +1 of the previous card

-me

##### Share on other sites
Well, i understand that and i am using numerical values for the cards.
and +1 from the previous card will only read it as a straight if the numbers are in a sequential order(1,2,3,4,5).
i need to know how to read (2,5,4,1,3) as a straight..

[Edited by - Bluseed on June 23, 2006 8:38:55 AM]

##### Share on other sites
So nevermind my last post i figured it out, i hate when i waste space, i shoulda just stared at it for another hour!! LOL

thx

[Edited by - Bluseed on June 23, 2006 8:51:38 AM]

##### Share on other sites
Dammit i spoke too soon: it doesnt work if you get 2,2,3,4,5 it says its a straight!!!

someone help??

##### Share on other sites
bool isFlush(hand)        for each card in your hand except for the last one                if the next card is not this card's value + 1                        return false        end for        return true

This assumes you sorted your cards.

##### Share on other sites
I had same problem with recognizing poker hands. What I did was use some logic...
I checked for flush based hands first, then 4 of a kind, then full house, then 3 of a kind, then 2 pair then pair. After all i basically sorted the array and said if the players hand was none of the above and hand[5] - hand[1] = 4 it was a straight.
This works for every straight except for the wheel (Ace thru 5).
So then I said if none of the above is true, and hand[5] is an ace and hand[4] - hand[1] = 3 then u have the wheel.

If you would like I can paste the code for you...I just have to find it.
If you can think of a better method for doin this let me know.

##### Share on other sites
Damn ok i c what you mean by sorting them, can u lead me somewhere that has some examples of how to sort numbers from lowest to highest, i just tried it on my own and i know im going about it the wrong way...

I would love to see some code plz....:)

The method i want to use:
I get random values for CardA,CardB,CardC,CardD,CardE then
i can sort the values from lowest to highest
(sounds so damn easy, im embarrassed) that way i can easily say,

[script]

SortCards(A,B,C,D,E);

if (E == D + 1 && D == C + 1 && C == B + 1 && B == A + 1) {
printf("You got a straight")
}

[/script]

##### Share on other sites
You can find sorting code by searching google for things like bubble sort, selection sort, insertion sort etc (or an easier solution is to use the qsort function where the quick sort algorithm is implemented for you with you only needing to give a 'comparison' function... see google).
The problem I'm seeing with your approach and sorting is that you're not using an array (or some other collection structure) to hold your cards.

I'm not sure what level of coding you're up to so I'm not sure if anything we've posted so far makes any sense. And at this point am assuming you're in C or C++ environment.

I suggest you read up on Loops, Arrays and Sorting (in that order). Google should turn up a trillion results for these :)

P.S. You may also want to take a look at Structs coz that'd be a nicer way to store your card data (either structs or classes, depending on if you're in c or c++)

##### Share on other sites
Well yah im not too far advanced and im using c++ i guess u can say im trying to figure this all out.
I know im running into a lot of questions myself knowing im doing some things wrong or the hard way, and nopw that you mention it , LOLOLOL , an array would be a lot better wouldnt it then i could just use a FOR statement. I was wondering how you would use a FOR statement with my code but i think that makes sense now. Trial and Error Trial and Error, thx for the tips and help appreciate it... im not totally noob, i use a lot of directX gfx, but really never got down and dirty into the logic portions which im trying to really dive into now.

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633346
• Total Posts
3011444
• ### Who's Online (See full list)

There are no registered users currently online

×