Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / help with poker game

Author
Message
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Mar 2009 03:02 Edited at: 23rd Mar 2009 03:14
hey im makin a poker game (as u read above) and im workin on the function for checking wat each player has, but i cant figure out a shorter way to check if five cards are the same suit (flush) or if 5 are consecutive (straight/run). The only way i can think of is to write out a long series of ifs and ands for every possible combo (a,b,c,d,e; or a,c,e,f,g are all same suit/consecutive) all the letters are in order from least to greatest (a=lowest, g=highest) and the suits are saved into asuit, bsuit, csuit, etc

also a,b,c... represent the result of (NumberOnCard-2)*4+Suit+1
the suit values are (spade=1,club=2,heart=3,diamond=4)

if fewer than 7 cards are visible to a player (2 in hand + 5 on table) then only that many letters are used
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 23rd Mar 2009 06:08
hmmmm select might make it easier but could you set up some arrays that have those same hands in them then use a select or maybe a for next depending on how the arrays are to check if the current hand is equal to the array hand?


like this



not sure if that would work though. never made a poker game

New Site! Check it out \/
feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 23rd Mar 2009 07:38 Edited at: 23rd Mar 2009 07:41
normally bits are used for this, look up logical AND, XOR, OR, and such for bits, I'm gonna use an array.


Get the picture? Later you'd test to see which variables are greater than 0, and you'd reset each test(n) to 0 before each loop to get an accurate check. It's not fast, but it's cleaner.

You could also make it easier to read by doing this:



To test later:

remember to test for the most important thing first. I haven't played poker in over a decade now... don't know what it is.

See what's going on there? I'm using an enum (enumeration) but hardcoding it to use a global integer, that way the number's recognized by the entire program (enums are too btw), then instead of writing numbers, I'm making it easy to read without needing comments.

Mind you Flush() would be your function that tests for a flush.

Hope that helps. My finished programs are all because I just stopped looking for the best way, and did it the dirty way, just so I'd finish the program. Sometimes it's better to do that. Good luck! I don't really visit DBC forums that much.

later

Signed
------
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 23rd Mar 2009 21:57
p.s. You don't need to have

for count = 1 to 6
test(count) = 0
next count

because DB automatically fills them w/ 0's. And, don't forget that arrays start at 0, not 1.

~QJ
That's what they WANT you to think...
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Mar 2009 23:11
Using a similar approach as feiting shadow, you could set up a single function to return the number of the type of poker hand, or rather, its value after passing the players hand to it.

Quote: "but i cant figure out a shorter way to check if five cards are the same suit (flush) or if 5 are consecutive (straight/run)."

When you think of all the details of which hand can contain what, and which is greater than this, you might overlook some of the basics. A deck of cards is already ranked - 1 through 52. It has a subranking of 13 - 2 through Ace; and another subranking of 4 - the suits. You can manage these ranks anyway you want and by doing that, you can return the value of any card.

So, every 13 cards is it's own suit. So if we rank the suits 0=spades; 1=clubs; 2=hearts; 3=diamonds then we can find or assign any card and know it's value:

suit=0
card=card value (1 through 52)
if card > 13 then suit=((card-1)/13)
rank=card-(suit*13)

If suit < 1 then we know it's spades
If suit < 2 and > 1 we know it's clubs
if suit < 3 and > 2 we know it's hearts
if suit >= 3 we know it's diamonds

By sending the player's card values to your function, you can easily figure out everything you need.

The rank is the value that identifies the card's worth. You compare values by using combinations of the rank values against your predefined table of poker hands. In your function, you'll always sort the ranks so you can easily pickup on pairs, straights whatever. You use the suit value to determine a flush.

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 24th Mar 2009 01:28
thats basically wat i ended up doing, sorta. i ranked each card 1-52 (2 of spades is 1, 2 of clubs is 3, hearts is 3rd, and diamonds is 4th) and used my ranking formula above (the only reason the +1 is there is cuz i wasnt thinking and saved an image of all the cards to image 1, so the formula actually represents the image number of each card) and i saved the suits into a number for flushes and the like. then i used an array full of flags saying whether or not a certain card is in the hand. so if card_in_hand(2)[2 would be he 2 of spades, the lowest rank of 2]=1 and card_in_hand(6)[the three of spades]=1... a straight flush is present.

Im also working in another array telling how many of one number are present in the hand, that would make pairs, three of a kind, and four of a kind easier to detect

another question, how many arrays is to many, cuz i think i have 10 in this code
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Mar 2009 21:52
A few tips:
It's better to sort the cards 0 to 51 because when you divide by 13 (as integer) you get 0 for 0-12; so those first 13 cards make up the spades suit (suit 0). And so on for the other suits. I don't know what Latch's <> stuff is about because you already have the suit once you've divided by 13.

To check for hands use your formulas for card value and suit. To look for a flush there are two ways; you could use a for loop and count the cards that are the same suit (remember 5 need to be the same and there are 7 available so if one suit check returns 3 or 4 it is impossible for another suit to be flush), or you could have a variable for each suit and keep a tally of them all as you check the cards.

For dealing you only need to check for cards that have already been dealt, making a separate array of 51 to store each cards deal status is fine but seeing as you're only going to have a max of 21 cards on the table I would just check the hands and river but I'm not sure which would be quicker.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 27th Mar 2009 23:32
again basically wat i was doin, however i do like the idea of sorting cards by suit, but im not sure if it would be faster than sorting by number like i have.

also im not worried about this right now cuz i made a mistake somewhere so now the top card value (Ace of Diamonds) shows an image designated for a chip

im thinkin really hard about starting over bcuz i didnt organize or rem my program very well and tracking bugs is getting hard

one quick q, is get image any faster than load image cuz im thinkin about saving each card image to a file and loading em reather than splitting up one image of all the cards, that way i dont have to worry about a card being one pixel too big/small and having to fix my math to fix it
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 27th Mar 2009 23:45
"<>"

means not equal to.

~QJ
That's what they WANT you to think...
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Mar 2009 02:07
@QJ
yeah i no I meant there's no need to use <> if you int() the division cos youll be left with the suit number.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Mar 2009 03:20 Edited at: 28th Mar 2009 03:34
Quote: "I don't know what Latch's <> stuff is about because you already have the suit once you've divided by 13."


Quote: "If suit < 1 then we know it's spades
If suit < 2 and > 1 we know it's clubs
if suit < 3 and > 2 we know it's hearts
if suit >= 3 we know it's diamonds"


Not code, just shorthand explaining that you'd know the suits by the value returned from the formula. Maybe easier to understand if written like: if suit = <number> then you know card suit is <whatever>

And upon knowing the suits of all the players cards, you'd know not to even look for a flush if all of the suits didn't match. A sort reveals the order and ranking. If there's a difference of 1 between each card rank, then it's a straight. The highest card determines the straight's value. If all the suits match, the same thing applies except the resulting score is higher for a flush.

The idea is not to compare players cards against players cards but to get a score for each players hand based on the cards that player has. The score determines who has the highest hand. If the the value ranking of any card is from 1 to 13 (2 through ace) then the first set of points is just the ranking added together. The next set of points is for whatever the scoring is. Maybe a pair is worth 14, 2 pair is worth 15, 3 of a kind is worth 16 - based on the poker ranking. The initial sort will always put the hand in order so like ranks will match up, sequences will be revealed, etc. Then depending on the matching, for example, a pair, add the value of 14 to the original set of points and then add the two cards ranks that were in the pair - say t threes. So the value of the hand would be:
the intital add up of all of the cards +
any hand values found +
the cards values of the cards in the hand rank
This will leave the player with the best hand with the highest value. So your function, would just return this value.

Enjoy your day.
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Mar 2009 01:10
@Latch
There's a problem with your hand "weighting" system, the principle is fine (you've explained it to me personally before ) but here's the thing:
In poker the rank of the hand is judged before the value of the highest card, so three 2's would beat a pair of aces. In the weighting: three 2's would get a score of 16+2 or something, and a pair of aces would get 14+13 and win, which is incorrect.
I know those weightings were just explaining the idea, I'm just shedding light on how complex poker is.
but how would we rectify this problem?
would you give every successive hand a weight of 14+the weight of the hand ranked below it? I think that might be it, thinking out loud here

and then you have the problem of Texas Hold'em, I'm just gonna leave that and code a standard poker game first.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 30th Mar 2009 03:18
what problem with hold 'em, thats wat the game is

right now i see two options for hand ranking, the first is basically wat u said, scoring the hand:

say that u had the pair of aces, ur hand would be 20 (just a generic start value for pairs) + the card value (14) so that pair would be worth 34, vs the trip 3s which would be 40 (generic start for trips) + card value (3) so trip 3s r worth 43

or reverse ranking the hand (highest rank is best hand):

start at rank 1 high card 2 (which is technically impossible but it needs to be there to keep the ranking intact) then rank 2 with high card 3, rank 3 with high card 4, going up with no space between hand types (high card ace + 1 = lowest pair (2s)). then just check if player_hand_rank(1) (player 1s hand) > than player_hand_rank(2)

but the scoring isnt the current problem, its how to check for those hands

btw i think i am starting all over and this time im gona organize and rem my code betr
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Mar 2009 03:57
This is a really good thing to make, I'm going to make a poker game
@smartguy
You need the higher ranked hands to beat the lower ranked hands, regardless of the value of the cards, that's the rules of poker. It's only when you have matching hands that the value of the cards comes into play.
Texas Hold'em is just one variation of poker, I wikipedia searched "poker" and there's quite a lot of good stuff there, some interesting variations on the game too.
"Draw" poker would be the easiest to make because each player is dealt 5 cards of their own so there's no communal cards to cross-check.

can't read?
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 31st Mar 2009 04:02
still, its not the checking for wat cards are in each players "communiy hand" isnt the problem, its checking if a hand is present

also, lets just discard this thread for now, im starting over on the game and ill post here if i run into a problem, so until then, just kinda ignore this thread
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 31st Mar 2009 05:11 Edited at: 31st Mar 2009 05:15
I can't let these statements pass without comment (I have a cold and I'm grumpy)

Quote: "In the weighting: three 2's would get a score of 16+2 or something, and a pair of aces would get 14+13 and win, which is incorrect."

Use your imagination people. Set the hand scoring high enough to compensate.

Quote: "You need the higher ranked hands to beat the lower ranked hands, regardless of the value of the cards"


The lowest ranking poker hand is the highest card so card value is a first and foremost necessary check. The value of the cards always should be taken into account.

@That1Smart Guy
Quote: "still, its not the checking for wat cards are in each players "communiy hand" isnt the problem, its checking if a hand is present"


and I know you want this abandoned for now but from the recent comments, there's not a full understanding of what I was trying to convey. The scoring system is the determiner of the hands and vice versa. Though you have to have a hand scoring high enough to compensate for the value of the cards. Each incremental hand could be in values of 200.

Highest card = 0
Pair = 200
2 pair = 400
3 of a kind = 600
etc.

All you need is subtraction to find the hand. That is, the difference between the indivdually sorted cards in the hand. I kept stressing the importance of sorting the player's hand. That's because the sort will put everything in order and help tell you what the player has.

The porcess might go like this:
deal the cards
-texas hold em style: create a hand by filling in the players empty slots (up to 7 right?) with the cards on the table plus the 2 they have.
-sort the players hand
-check the suits - if the same, possible flush
-check highest card - if > 6 then a possible straight
-find the difference between cards (abs(card2-card1), abs(card3-card2), abs(card4-card3), abs(card5-card4) etc if more than 5)
-if the difference is 0, you have 2 of the same cards. If there are two differences of 0 in a row, you have 3 matching cards etc.
if there is a difference of 1 between all of the cards, you have a straight. The high card and the suit check you did earlier will tell you if you have a straight flush of royal flush.
-keeping track of the differences and the card value will spell out your hands. If you had a difference of 0 between card2-card1, and a difference of 0 between card4-card3, then you would have 2 pair. Understand? The differences between the sorted cards tell you the hand, and/or a set of matching suits tell you the hand. So it becomes very important to know the value (1-13) of the card so you can find those differences. Then the value of the hand is added to the card rank : 3 of a kind 5s = 600 + 6

As you find the differences between the cards in the hand, you test what the hand is. Because I'm fading into dizzyness, this example is clunky, but shows the idea. I use the difference between cards with the idea that you would use 1 routine to test the hand as opposed to how I did the test twice - still shows you what's going on:



there's a counting error in the check for hands part, I'm too blind to see it right now so 3 of kind and up may error.

Enjoy your day.
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Mar 2009 07:25
@Latch
sorry i was kind of prodding at your example there :-(
That was the most helpful rant I've ever seen
The sorting is clever and makes a lot of sense, I think I can make a poker game now how about smartguy?

can't read?
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 31st Mar 2009 17:18
i like the idea, and i may try to start with that draw poker or watever it was, at least for my 1st card game, then ill come back to hold'em
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 9th Apr 2009 04:16 Edited at: 9th Apr 2009 04:16
having trouble with my check for a hand function, i keep getting errors bcuz im outputting my string wrong or something, sorry for lack of much code but heres the function, ask stuff and ill explain nething i can



There are only 10 kinds of people in the world, those who understand binary and those who dont
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 9th Apr 2009 22:59
Instead of

Use


That's what they WANT you to think...
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Apr 2009 23:21
+Str$(G)

you can't add a integer to a string

New Site! Check it out \/
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 10th Apr 2009 22:55
That, too.

That's what they WANT you to think...

Login to post a reply

Server time is: 2025-08-08 20:42:36
Your offset time is: 2025-08-08 20:42:36