Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > Internet Gambling > Software
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2006, 04:39 PM
NewUser2006 NewUser2006 is offline
Senior Member
 
Join Date: Apr 2006
Posts: 897
Default 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.
Reply With Quote
  #2  
Old 07-14-2006, 07:35 PM
Dadswell Dadswell is offline
Senior Member
 
Join Date: Jun 2006
Location: Canada
Posts: 763
Default Re: Algorithm for Figuring out Your Hold\'em Hand

trying to code up a bot?
Reply With Quote
  #3  
Old 07-14-2006, 07:59 PM
StumpyJoe StumpyJoe is offline
Junior Member
 
Join Date: Jan 2006
Posts: 22
Default 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
Reply With Quote
  #4  
Old 07-14-2006, 08:04 PM
PartyGirlUK PartyGirlUK is offline
Senior Member
 
Join Date: Nov 2004
Posts: 10,995
Default 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.
Reply With Quote
  #5  
Old 07-14-2006, 08:22 PM
NewUser2006 NewUser2006 is offline
Senior Member
 
Join Date: Apr 2006
Posts: 897
Default 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]
Reply With Quote
  #6  
Old 07-14-2006, 08:36 PM
NewUser2006 NewUser2006 is offline
Senior Member
 
Join Date: Apr 2006
Posts: 897
Default 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.
Reply With Quote
  #7  
Old 07-17-2006, 05:53 PM
NewUser2006 NewUser2006 is offline
Senior Member
 
Join Date: Apr 2006
Posts: 897
Default 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&lt;Card&gt; holeCards;
holeCards.push_back(thePlayer-&gt;getHoleCard(0));
holeCards.push_back(thePlayer-&gt;getHoleCard(1));

//stores the board cards
vector&lt;Card&gt; boardCards;
for(int i = 0; i &lt; 5; ++i){
boardCards.push_back(theBoard-&gt;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&lt;Card&gt; allCards;
allCards.push_back(holeCards[0]);
allCards.push_back(holeCards[1]);

for(int i = 0; i &lt; 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 &gt;= 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 &gt;= 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 &lt; 7; ++j){
for(int i = 0; i &lt; 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 &amp;&amp; (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 &gt;= 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 &gt;= 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 />
Reply With Quote
  #8  
Old 07-17-2006, 06:54 PM
MrMoo MrMoo is offline
Senior Member
 
Join Date: Sep 2004
Location: Las Vegas
Posts: 750
Default Re: Algorithm for Figuring out Your Hold\'em Hand

Here. See the hand evaluator section.
Reply With Quote
  #9  
Old 07-17-2006, 07:53 PM
NewUser2006 NewUser2006 is offline
Senior Member
 
Join Date: Apr 2006
Posts: 897
Default Re: Algorithm for Figuring out Your Hold\'em Hand

[ QUOTE ]
Here. See the hand evaluator section.

[/ QUOTE ]

Oooooo slick. Thanks.
Reply With Quote
  #10  
Old 07-18-2006, 04:26 AM
bdiddy12 bdiddy12 is offline
Senior Member
 
Join Date: Feb 2006
Posts: 690
Default 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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.