Example #1
0
// This one is not fully optimized
PokerEvaluation CardSet::evaluateLow2to7() const
{
    PokerEvaluation high;

    // if there are five or fewer cards, we just evaluate the high,
    // fix the wheel, and take the complement
    switch (size())
    {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
        high = evaluateHigh();
        break;

    case 5:
        high = evaluateHigh();
        high.fixWheel2to7(rankMask());
        break;

    default:
        // this is a slow way to handle the general case.
        // TODO: specialize the code for the 6 and 7 card cases.
        vector<Card> cards = this->cards();
        combinations combo(size(), FULL_HAND_SIZE);
        PokerEvaluation best;
        do
        {
            CardSet candidate;
            for (size_t i=0; i<static_cast<size_t>(FULL_HAND_SIZE); i++)
                candidate.insert(cards[combo[i]]);
            PokerEvaluation e = candidate.evaluateLow2to7();
            if (e > best)
                best = e;
        }
        while (combo.next());
        return best;

    }

    high.flip();
    return high;
}