views:

1185

answers:

6

I'm looking for code or a description of an algorithm for determining the score of a poker hand when deuces are wild. I'd like code that is not encumbered by license fees, GPL, patents, etc.

I know a couple of ways to approach this, but I'd prefer to not write the code if it is already available somewhere. So I'd appreciate it if the answers are confined to links to actual working code or detailed algorithmic descriptions.

(I'm not asking anyone to "do my homework for me." I can write the code myself, so pseudocode and implementation suggestions are not needed. I just don't want to waste time solving an already-solved problem.)

+4  A: 

I think because you said you specifically don't want ideas you just want a working solution.

I think that the common thought is that it's best to do it the most efficient attractive way not just the way that some guy did it before that works. I think one of the advantages to this community is the pool of programmers that can bounce ideas around and help lead you to the best way of doing something.

I think that most of us are emotional about our codebase and wonder what the motivation of someone would be that would throw just any-old-thing-that-works into theirs.

Is this for a homework assignment? Or possibly for someone else?

Sara Chipps
+1  A: 

My guess is you are down-voted because you "[...] want actual working code [...]", which may sound a bit like "send me the codes".

Also, it might help to explain what you mean by "scoring a poker hand" and "deuces are wild". Are you making a poker AI?

Anders Sandvig
+2  A: 

There's a difference between " Can you tell me how do.." and "Do this for me." Demonstrate some willingness to do some effort yourself.

Rik
+3  A: 

Without writing all the code, a start would look something like:

/*
* 2.1 Straight flush
* 2.2 Four of a kind
* 2.3 Full house
* 2.4 Flush
* 2.5 Straight
* 2.6 Three of a kind
* 2.7 Two pair
* 2.8 One pair
* 2.9 High card
*/
// Note, the vector cards is sorted low to high. All cards have a numeric value 2-13 and a suit 0-3
int noDuces(Cards[] cards) {
    int duces = 0;
    int cursor = cards.length;
    while(cards[cursor--].value == 2) duces++;
    return duces;
}

bool isFlush(Cards [] cards) {
   int duces = noDuces(cards);
   int firstColour = cards[cards.length].colour;
   for (int i = cards.length -1; i > duces; i--) {
       if (cards[i].colour != firstColour)
        return false;
   }
   return true;
}

bool isStraight(Cards[] cards) {
    int duces = noDuces(cards);
    int usedDuces = 0;
    // TODO Handle A - 5 straight. 
   card prevCard = cards[cards.length];
    for (int i = cards.length -1; i > duces; i--) {
       if ((prevCard.value + 1) != cards[i].value) {
        if (usedDuces >= duces) {
         return false;
        }
        usedDuces++;
       }
       prevCard = cards[i];
   }
    return true;
}
Tnilsson
This doesn't seem to cover five of a kind.
David Locke
+1  A: 

http://www.codingthewheel.com/archives/poker-hand-evaluator-roundup

Page about poker eval libraries. - list of libraries/algorithms

ralu
+2  A: 

Complete source code for Texas hold'em poker game evaluator can be found here:

http://www.advancedmcode.org/poker-predictor.html

It is built for matlab, the GUI id m-coded but the computational engine is c++.

It allows for odds and probability calculation. It can deal, on my 2.4Ghz laptop, with a 100000 10 players game computation in 0,3 seconds.

An accurate real time computer:-)

Luigi Giaccari