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, 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
  #4  
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
  #5  
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
  #6  
Old 07-25-2006, 04:07 PM
disjunction disjunction is offline
Senior Member
 
Join Date: Nov 2004
Posts: 3,352
Default Re: Algorithm for Figuring out Your Hold\'em Hand

[ QUOTE ]
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.

[/ QUOTE ]

I've written this type of code. It's more tedious and more open for interpretation than you'd think. The problem is how to label the various straight draws and gutshots mixed in with overcards.
Reply With Quote
  #7  
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
  #8  
Old 07-26-2006, 09:20 AM
Shroomy Shroomy is offline
Senior Member
 
Join Date: Apr 2006
Location: Miami FLA
Posts: 465
Default Re: Algorithm for Figuring out Your Hold\'em Hand

[ QUOTE ]
Also, I just want an algorithm, not actual code. I'm really just trying to keep my programing skills sharpened during the summer.

[/ QUOTE ]

step 1 create a table of all valid hands starting with lowest (2,3,4,5,7) so it returns 1 and ending with highest (royal flush) so it returns 7462

step 2
if the score is 1-1277 its a highcard hand (no pair)
if the score is 1278 - 4137 its a one pair hand
etc..
if the score is 7452 - 7462 it is a straight flush

You can get more detailed if you want like 1124-1277 is an Ace high hand.

and look here http://forumserver.twoplustwo.com/showfl...e=0#Post6652490
Reply With Quote
  #9  
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
  #10  
Old 07-25-2006, 04:12 PM
disjunction disjunction is offline
Senior Member
 
Join Date: Nov 2004
Posts: 3,352
Default Re: Algorithm for Figuring out Your Hold\'em Hand

If you're going to do this for a living, the most important lesson you can learn is that no one will EVER through your code. This is important for email communications. Reading someone else's code is actually harder in some sense than writing your own.

I am not trying to be cute -- I made this mistake as an intern.

Also, an important skill is to able to write adequate tests for your code and debug it. Bad engineers skip this part too often. Poker code is good practice for this.



[ QUOTE ]
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 />

[/ QUOTE ]
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 11:15 PM.


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