You are invited to Log in or Register a free Frihost Account!

# Poker

snowboardalliance
I was just curious, in my ocmputer programming class we had made a 5 card poker game in C++, but I wanted to make texas hold'em on my own now just for fun. I want to know if anyone has advice/resources on how to do it.
The biggest problem being finding the BEST hand out of 7 cards. I have a way to "rank" a hand correctly, but only for 5 cards, and this would require the best 5 out of 7. I can't think of a better way than actaully trying all (21?) hands.
Secondly, how would I go about doing AI if I chose to. This is a lot more difficult of course but if anyone knows how to make AI that bet using thier odds and bluff etc. that would be awesome.

Again, I'm just asking for some sites or tutorials to help, but if you could explain, that is good enought too.

Thanks
AftershockVibe
Trying all 21 hands is certainly the easiest way to do it.

I might try something like the following though (not to say this is necessarily the best way!)

I would make the cards as objects and then sort them into two lists (vectors, whatever);
1. order by suit
2. order by value (highest card first).

Then it becomes very easy to check downwards through the hands.
- Check for straight by looking in 2 (if more than one is found check for a flush with the same cards in 1 to choose which, otherwise pick the first found (the highest!))
- Check for flush by looking in 1
- Check for 4 of a kind, 3 of a kind and pair
- (remember to combine for full house)
- If nothing found return the highest card in 2

The 4 of a kind... pair checking can be done quickly by creating a map for each card value in the hand to an integer and then incrementing for each one you have.

AI can be done by weighting probability of winning. You can work out percentages for possible hands for the AI and compare it against the probability of the AIs opponents two unknown cards making better hands.
snowboardalliance
 AftershockVibe wrote: Trying all 21 hands is certainly the easiest way to do it. I might try something like the following though (not to say this is necessarily the best way!) I would make the cards as objects and then sort them into two lists (vectors, whatever); 1. order by suit 2. order by value (highest card first). Then it becomes very easy to check downwards through the hands. - Check for straight by looking in 2 (if more than one is found check for a flush with the same cards in 1 to choose which, otherwise pick the first found (the highest!)) - Check for flush by looking in 1 - Check for 4 of a kind, 3 of a kind and pair - (remember to combine for full house) - If nothing found return the highest card in 2 The 4 of a kind... pair checking can be done quickly by creating a map for each card value in the hand to an integer and then incrementing for each one you have. AI can be done by weighting probability of winning. You can work out percentages for possible hands for the AI and compare it against the probability of the AIs opponents two unknown cards making better hands.

OK, I already have all the system of checking, but doing 21 checks is ok? I'll just go that route. And yes, I did it with objects.

Now with the AI part, do you have any source on poker probability? I'm not that good with probability and in poker, it's pretty complex. If you have any resources on this or feel you can really explain it well, that would be awesome. THanks
NewGuyinTown
 snowboardalliance wrote: Now with the AI part, do you have any source on poker probability? I'm not that good with probability and in poker, it's pretty complex. If you have any resources on this or feel you can really explain it well, that would be awesome. THanks

I'm not sure what is it that you're asking here, but I think you're asking for an algorithm or procedure that distribute a random card to a player's hand.

OK... I know JAVA and starting assembly languages. C++, I believe, is somewhere in between. Basically, I don't know how much restrictions or freedoms there is in C++ and C.

In JAVA, I would normally build a Player class, create 21 of these objects (one for each player) during run-time. If this is avialible in C++ and you did this, your logic is on the right track so far.

Normally there 52 cards to a deck of cards. 13 spades,hearts,clubs,diamonds of different numbers. I don't know how much decks they used in poker...

So, I would create a Card Class and create a deck procedure, which create 52 Cards, and put these Card objects into an arraylist. Shuffle them. I would use the random integer generator to generate an integer from 0 to number of non-null elements in the array -1 is. The integer generated will be used to distribute the Card at the nth element of the array to the Player. Move the last element to fill the vacant space the card has left. -1 to number of elements. Shuffle. Loop it.

To generate cards base on probability and on the go means there are infinitely many decks.

Each number (A,2,3,4,5,6,7,8,9,J,Q,K) have a probability of 1/13. Each ???? (spades, hearts, clubs, diamonds) have a probability of 1/4.

I really don't understand what probability you are referring to if it's not about the distribution of random cards to a player's hand.
HoboBarticus
I believe you are asking for the probability of winning hands and the like? That way the AI knows what to do, correct?

If so, then by even asking, you are way out of your league on that one. Programming a Poker Player, let alone a competent one, will take quite a bit of work.

If it is what you're looking for then, yeah sure, Ill post some odds up here. If not, forget what I said.

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.