#1
|
|||
|
|||
Algorithm for Figuring out Your Hold\'em Hand
I was just wondering if anyone could point me in the right direction to an algorithm that figures out your best 5-card hand at the end of the hand.
Also, do any of you have any good ideas for expressing different hand values? I was thinking of making a few enumerated values for each of the main "types" of hands, then doing card-by-card comparisons if any two players' hands match. For instance, something like this: enum HANDRANK { NOPAIR = 0, ONEPAIR = 1, TWOPAIR = 2, THREEKIND = 3, STRAIGHT = 4, FLUSH = 5, FULLHOUSE = 6, FOURKIND = 7, STRAIGHTFLUSH = 8}; And then comparing the values to see who won. Any better ways to do this? Thanks. |
#2
|
|||
|
|||
Re: Algorithm for Figuring out Your Hold\'em Hand
trying to code up a bot?
|
#3
|
|||
|
|||
Re: Algorithm for Figuring out Your Hold\'em Hand
There is some open source code that will do exactly what you're looking for. Just look around on Sourceforge.
To the bot accuser. Anyone capable of writing a bot that is worth worrying about wouldn't need to ask how to write code to determine what kind of hand he has. StumpyJoe |
#4
|
|||
|
|||
Re: Algorithm for Figuring out Your Hold\'em Hand
I might be interested in some sort of code to work out how strong a hand is with less than 7 cards. So say after turn, it could classify the hands as 'two pair' or 'two pair with flush draw' or 'flush draw' etc.
|
#5
|
|||
|
|||
Re: Algorithm for Figuring out Your Hold\'em Hand
[ QUOTE ]
trying to code up a bot? [/ QUOTE ] sorta, but I'd call it a simulation more than a bot. right now i've got 9 opponents who randomly decide whether to bet raise or fold [img]/images/graemlins/smile.gif[/img] |
#6
|
|||
|
|||
Re: Algorithm for Figuring out Your Hold\'em Hand
Also, I just want an algorithm, not actual code. I'm really just trying to keep my programing skills sharpened during the summer.
|
#7
|
|||
|
|||
Re: Algorithm for Figuring out Your Hold\'em Hand
In case anyone was wondering... here is the code I came up with. I still have to find a way to check for A2345 straights and straightflushes, since I made the Ace count as high when I coded it.
<font class="small">Code:</font><hr /><pre> HAND evalHand(Player * thePlayer, Board * theBoard) { //stores the player's hole cards vector<Card> holeCards; holeCards.push_back(thePlayer->getHoleCard(0)); holeCards.push_back(thePlayer->getHoleCard(1)); //stores the board cards vector<Card> boardCards; for(int i = 0; i < 5; ++i){ boardCards.push_back(theBoard->at(i)); } sort(boardCards.begin(), boardCards.end()); //add holecards to form a "total" hand, they are left seperate for "incomplete" hand evaluation //later on in a different function vector<Card> allCards; allCards.push_back(holeCards[0]); allCards.push_back(holeCards[1]); for(int i = 0; i < 5; ++i){ allCards.push_back(boardCards[i]); } sort(allCards.begin(), allCards.end(), sortBySuit()); //first sort by suit to check for straightflush //------begin checking hands-------------------- //************check for flush or straightflush********************* bool flush = false; Card c = allCards[6]; int flushCount = 1, straightFlushCount = 1; int flushIndex= 6, straightFlushIndex = 6; for(int i = 5; i >= 0; --i){ //loop through the array backwards, checking the highest card first if(c.getSuit() == allCards[i].getSuit()){ //next in flush if(c.getRank() - allCards[i].getRank() == 1){ //straight-flush count straightFlushCount++; //begin building straightflush flushCount++; } else { //no straight-flush, but still could be flush straightFlushCount = 1; straightFlushIndex = i; flushCount++; } } else { //no flush or straightflush straightFlushCount = 1; straightFlushIndex = i; if(!flush){ //don't reset flush counts if we already have one flushCount = 1; flushIndex = i; } } if(flushCount >= 5){ //flush! if(straightFlushCount == 5) { //could be a straight-flush return STRAIGHTFLUSH; } else { flush = true; //can't return yet since we have to check for rest of straightflush, //quads or fullhouse } } c = allCards[i]; } //*********check for four of a kind, trips, two pair, one pair****************** int threeKind = 0, pair = 0; int pairCount[7] = {1,1,1,1,1,1,1}; for(int j = 0; j < 7; ++j){ for(int i = 0; i < 7; ++i){ if(i != j){ if(allCards[j].getRank() == allCards[i].getRank()){ pairCount[j]++; } } } if(pairCount[j] == 4){ return FOURKIND; } else if(pairCount[j] == 3){ threeKind++; } else if(pairCount[j] == 2){ pair++; } } //*************check for full house********************** if((threeKind == 3 && (pair == 2 || pair == 4)) || threeKind == 6){ return FULLHOUSE; } //*************check for flush*************************** if(flush){ return FLUSH; } //**************check for straight******************* sort(allCards.begin(), allCards.end()); //now sort by rank to check for straight int straightCount = 1, straightIndex = 6; c = allCards[6]; for(int i = 5; i >= 0; --i){ //loop through the array backwards, checking the highest card first if(c.getRank() - allCards[i].getRank() == 1){ //next in the straight straightCount++; //if there is not a pair, reset straight counts and straightflush counts } else if(c.getRank() != allCards[i].getRank()){ straightCount = 1; straightIndex = i; } if(straightCount >= 5){ //straight! return STRAIGHT; } c = allCards[i]; } //*************check for trips********************** if(threeKind == 3){ return THREEKIND; } //************check for two pair******************** if(pair == 4 || pair == 6){ return TWOPAIR; } //***********check for one pair********************* if(pair == 2){ return ONEPAIR; } //***************HIGH CARD*************** return HIGHCARD; } </pre><hr /> |
#10
|
|||
|
|||
Re: Algorithm for Figuring out Your Hold\'em Hand
I did this in a warcraft 3 map (I had no life for a summer). I made a pretty sick 5-card draw bot.
|
|
|