bool full_house_tiebreak(const Hand &first,const Hand &second){ debug("Entered full_houe_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); int three1 = -1, two1 = -1, three2 = -1, two2 = -1; //Find the three and two combinations in first hand if(vec1[0].c_rank == vec1[1].c_rank && vec1[1].c_rank == vec1[2].c_rank){ three1 = vec1[0].c_rank; two1 = vec1[4].c_rank; } else{ three1 = vec1[4].c_rank; two1 = vec1[0].c_rank; } //Find the three and two combinations in second hand if(vec2[0].c_rank == vec2[1].c_rank && vec2[1].c_rank == vec2[2].c_rank){ three2 = vec2[0].c_rank; two2 = vec2[4].c_rank; } else{ three2 = vec2[4].c_rank; two2 = vec2[0].c_rank; } if(three1 != three2) //Compare three of a kind in the hands return three1 > three2; else if(two1 != two2) //Compare two of a kind in the hands return two1 > two2; //Hands have same poker rank return false; }
bool no_rank_tiebreak(const Hand &first,const Hand &second){ debug("Entered no_rank_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); for(int i = 4; i >= 0; --i){ if(vec1[i] < vec2[i]) return false; else if(vec2[i] < vec1[i]) return true; } return false; }
void GeneralPlayer::getFlushRank(Hand& table, GeneralPlayer::HandRating& handRating, const Card::suit suit) { Hand showDownHand; showDownHand.add(m_cards); showDownHand.add(table.getHand()); vector<Card*> showDownCards = showDownHand.getHand(); for (int i = 12, j = 0; j < 5; ++j) { if (showDownCards[i]->getSuit() == suit) handRating.kickerRank[j] = i; } }
bool flush_tiebreak(const Hand &first,const Hand &second){ debug("Entered flush_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); //Start at the end of each hand, and compare card values for(int i = 4; i >= 0; --i){ if(vec1[i].c_rank != vec2[i].c_rank) { if(vec1[i].c_rank > vec2[i].c_rank) return true; else return false; } } return false; }
bool pair_tiebreak(const Hand &first,const Hand &second){ debug("Entered pair_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); int rank1, rank2; //obtain which is the pair rank in each hand for(size_t i = 0; i < vec1.size()-1; ++i){ if(vec1[i].c_rank == vec1[i+1].c_rank){ rank1 = vec1[i].c_rank; break; } } for(size_t i = 0; i < vec2.size()-1; ++i){ if(vec2[i].c_rank == vec2[i+1].c_rank){ rank2 = vec2[i].c_rank; break; } } //Pair card ranks are not the same - return true if first pair is greater if(rank1 != rank2) return rank1 > rank2; //Collect the remaining three cards from each hand for comparison vector<int> firstRanks,secondRanks; for(size_t i = 0; i < vec1.size(); ++i){ if(vec1[i].c_rank != rank1){ firstRanks.push_back(vec1[i].c_rank); } } for(size_t i = 0; i < vec2.size(); ++i){ if(vec2[i].c_rank != rank2){ secondRanks.push_back(vec2[i].c_rank); } } sort(firstRanks.begin(),firstRanks.end()); sort(secondRanks.begin(),secondRanks.end()); for(int i = 2; i >= 0; --i){ //Compare remaining cards if(firstRanks[i] != secondRanks[i]) { if(firstRanks[i] > secondRanks[i]) return true; else return false; } } return false; }
int getHandRank(const Hand &cards){ vector<Card> vec = cards.getHand(); Card c1 = vec[0],c2 = vec[1],c3 = vec[2],c4 = vec[3],c5 = vec[4]; int result; //Takes a hand of cards and checks the rank if(isStraightFlush(c1,c2,c3,c4,c5)) result = STRAIGHT_FLUSH; else if(isFourOfAKind(c1,c2,c3,c4,c5)) result = FOUR_OF_A_KIND; else if(isFullHouse(c1,c2,c3,c4,c5)) result = FULL_HOUSE; else if(isFlush(c1,c2,c3,c4,c5)) result = FLUSH; else if(isStraight(c1,c2,c3,c4,c5)) result = STRAIGHT; else if(isThreeOfAKind(c1,c2,c3,c4,c5)) result = THREE_OF_A_KIND; else if(isTwoPair(c1,c2,c3,c4,c5)) result = TWO_PAIR; else if(isPair(c1,c2,c3,c4,c5)) result = PAIR; else result = NO_RANK; return result; }
bool four_of_a_kind_tiebreak(const Hand &first,const Hand &second){ debug("Entered FOAK_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); int rank1 = vec1[2].c_rank; //guaranteed to be part of the 4oaK int rank2 = vec2[2].c_rank; //guaranteed to be part of the 4oaK //Compare the FoaK card ranks if(rank1 != rank2) return rank1 > rank2; //FoaK card ranks are equal, remaining card will be on either front //or end of each hand (because they are sorted) int other1 = (vec1[0].c_rank == vec1[1].c_rank) ? vec1[4].c_rank : vec1[0].c_rank; int other2 = (vec2[0].c_rank == vec2[1].c_rank) ? vec2[4].c_rank : vec2[0].c_rank; return other1 > other2; }
bool three_of_a_kind_tiebreak(const Hand &first,const Hand &second){ debug("Entered TOAK_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); int rank1, rank2; //3oaK values from each hand //Find the 3oaK values from each hand for(int i = 0; i < 4; ++i){ if(vec1[i].c_rank == vec1[i+1].c_rank) rank1 = vec1[i].c_rank; if(vec2[i].c_rank == vec2[i+1].c_rank) rank2 = vec2[i].c_rank; } //compare the 3oaK values if(rank1 != rank2) return rank1 > rank2; //3oaK values same, find remaining cards vector<int> firstRem,secondRem; for(int i = 0; i < 5; ++i){ if(vec1[i].c_rank != rank1) firstRem.push_back(vec1[i].c_rank); if(vec2[i].c_rank != rank2) secondRem.push_back(vec2[i].c_rank); } sort(firstRem.begin(),firstRem.end()); sort(secondRem.begin(),secondRem.end()); for(int i = 1; i >= 0; --i){ //Compare remaining cards if(firstRem[i] != secondRem[i]) { if(firstRem[i] > secondRem[i]) return true; else return false; } } return false; }
void GeneralPlayer::countSuits(int suitCount[], Hand& table) { vector<Card*> tableCards; tableCards = table.getHand(); for (int i = 0; i < m_cards.size(); ++i) { suitCount[m_cards[i]->getSuit()]; } for (int i = 0; i < tableCards.size(); ++i) { suitCount[tableCards[i]->getSuit()]; } }
void GeneralPlayer::countRanks(int rankCount[], Hand& table) { vector<Card*> tableCards; tableCards = table.getHand(); for (int i = 0; i < m_cards.size(); ++i) { rankCount[m_cards[i]->getRank()]++; } for (int i = 0; i < tableCards.size(); ++i) { rankCount[tableCards[i]->getRank()]; } }
bool straight_flush_tiebreak(const Hand &first,const Hand &second){ debug("Entered straight_flush_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); //For straight flush, just need to check the last card return vec1[4].c_rank > vec2[4].c_rank; }
bool straight_tiebreak(const Hand &first,const Hand &second){ debug("Entered straight_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); //For a straight, we just need to compare the last card of each hand return vec1[4].c_rank > vec2[4].c_rank; }
bool two_pair_tiebreak(const Hand &first,const Hand &second){ debug("Entered two_pair_tiebreak pointer"); vector<Card> vec1 = first.getHand(), vec2 = second.getHand(); int lp1 = -3, hp1 = -3, lp2 = -3, hp2 = -3; //Find the two pair ranks from first hand for(int i = 0; i < 4; ++i){ if(vec1[i].c_rank == vec1[i+1].c_rank){ if(lp1 == -3){ lp1 = vec1[i].c_rank; ++i; } else{ hp1 = vec1[i].c_rank; break; } } } //Find the two pair ranks from second hand for(int i = 0; i < 4; ++i){ if(vec2[i].c_rank == vec2[i+1].c_rank){ if(lp2 == -3){ lp2 = vec2[i].c_rank; i++; } else{ hp2 = vec2[i].c_rank; break; } } } if(lp1 > hp1){ //lp1 should be the smaller, swap if it isn't int swap = lp1; lp1 = hp1; hp1 = swap; } if(lp2 > hp2){ //lp2 should be the smaller, swap if it isn't int swap = lp2; lp2 = hp2; hp2 = swap; } //compare highest pair from each hand if(hp1 != hp2){ return hp1 > hp2; } //compare lower pair from each hand else if(lp1 != lp2){ return lp1 > lp2; } //both pairs are the same, find remaining card from each hand int remaining1 = -1, remaining2 = -1; for(int i = 0; i < 5; ++i){ if(vec1[i].c_rank != lp1 && vec1[i].c_rank != hp1) remaining1 = vec1[i].c_rank; if(vec2[i].c_rank != lp2 && vec2[i].c_rank != hp2) remaining2 = vec2[i].c_rank; } //compare remaining cards if(remaining1 != remaining2){ return remaining1 > remaining2; } //hands have the same poker rank return false; }