// This one is not fully optimized PokerEvaluation CardSet::evaluateRanksLow2to7() const { PokerEvaluation high; PokerEvaluation h; // 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 = evaluateHighRanks(); break; case 5: high = evaluateHighRanks(); 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.evaluateRanksLow2to7(); if (e > best) best = e; } while (combo.next()); return best; } high.flip(); return high; }
// This one is not fully optimized PokerEvaluation CardSet::evaluateLowA5() const { //PokerEvaluation::generateLowballLookupA5(); // this is a rank only evaluator, so we just get // the rank masks and then fill accordingly. We // also have to shift the rank mask according to the // the fact that the ace swings low // this could probably be much faster int c = C(); int d = D(); int h = H(); int s = S(); int rankmask = c | d | h | s; int ncards = nRanksTable[c] + nRanksTable[d] + nRanksTable[h] + nRanksTable[s]; int ndups = ncards - nRanksTable[rankmask]; int nranks = nRanksTable[rankmask]; // first the easy cases // 1) no duplicate ranks // 2) 5 or more ranks if (ndups == 0 || nranks >= FULL_HAND_SIZE) { PokerEvaluation ret((NO_PAIR<<VSHIFT) ^ lowballA5Ranks[rankmask] ^ ACE_LOW_BIT); ret.flip(); return ret; } // another easy case // *) we have five or fewer cards else if (ncards <= FULL_HAND_SIZE) { PokerEvaluation ret = evaluatePairing(); ret.playAceLow(); ret.flip(); return ret; } else { // now the general case // the algorithm is as follows: // cycle through the "pairing list" till a total of five // cards are found uint64_t chash = 0;// = rankmask; int rset[4]; rset[0] = rankmask; rset[1] = rankmask ^(c ^ d ^ h ^ s); // mask of cards with 2/4 ranks rset[2] = ((c&d)|(h&s)) & ((c&h)|(d&s)); // mask of cards with 3 ranks rset[3] = c & d & h & s; // fourmask rset[1] |= rset[2]; // add the threes back to teh twos rset[0] = LOWBALL_ROTATE_RANKS(rset[0]); rset[1] = LOWBALL_ROTATE_RANKS(rset[1]); rset[2] = LOWBALL_ROTATE_RANKS(rset[2]); rset[3] = LOWBALL_ROTATE_RANKS(rset[3]); // we add pairs first, then trips, then quads int nc=0; for (int i=0; i<4; i++) { // do the ace first if (rset[i] & (0x01<<Rank::AceVal())) { chash |= (ONE64<<(Rank::AceVal()+Rank::NUM_RANK*i)); nc++; } if (nc == FULL_HAND_SIZE) { break; } // now the rest of the ranks for (int r=0; r<11; r++) { if (rset[i] & (0x01<<r)) { chash |= (ONE64<<(r+Rank::NUM_RANK*i)); nc++; } if (nc == FULL_HAND_SIZE) { break; } } if (nc == FULL_HAND_SIZE) { break; } } CardSet paird(chash); PokerEvaluation ret(paird.evaluatePairing().code() | ACE_LOW_BIT); ret.flip(); return ret; } }