Numerical sorting?

Blitz3D Forums/Blitz3D Beginners Area/Numerical sorting?

tdman(Posted 2004) [#1]
I'm doing a bit of Blitz in my spare time, and have decided to write a Video Poker game.

When it comes to calculating whether you have a winning hand, and what that hand is, I'm a little confused.

Obviously I could go and write code for each individual possible hand, but that is far from efficient.

Say for instance I have - at the end of your hand being dealt - 5 strings, each of which contains the value of the card:

card_1_value = 12
card_2_value = 5
card_3_value = 14
card_4_value = 7
card_5_value = 14

The values I am using are as follows:

2 to 10 - self explanatory
Jack - 11
Queen - 12
King - 13
Ace - 14

How can I check these values and determine what poker hand I have? One pair, Two Pairs, Three of a kind, Flush, Straight, Full House, Straight Flush, Royal Flush are what I would like to check for.

If anyone can advise me, or point me in the right direction, I would be very grateful :)

Thanks!


JazzieB(Posted 2004) [#2]
One (part) solution that immediately comes to mind is to have an array that represents the count for each value of card (i.e. the 2-14 that you have, although it would be 0-12 because of where element numbering starts) and a second for the suits (just 0-3).

Then you could determine a pair by there being one or more card values with a count of 2. Three of a kind would mean one having 3.

A flush would be one suit having a count of however many make a flush up (this probably depends on the type of Poker you're playing).

A straight would entale consecutive card values having a count of 1. A straight flush would also have this along with a count of the total number of cards in a hand in one suit.

After the card value and suit count-up, you'd make the above checks in the highest winning hand down to the lowest. Alright, I've not included all the possibilities here, but I hope it's enough to get you thinking in one possible direction.


TomToad(Posted 2004) [#3]
Possibly an array of types?



after that you would do something to shuffle the deck, then deal the cards using something like


basically, t is the player (0-4 so 5 players total) and j is the card (5 cards).
Then after the player chooses which cards to discard, you deal the player some more always updating cardcount each time one is dealt. Also some betting mechanism and so forth. Then when it's time to check the hands:


Now this method assumes that ace is high. If you're playing Ace as either high or low, then you need to make provisions for that when you check for the straight.

Edited because I realized my code example would check for a flush and straight flush, but not a straight. :-)