void getRank() { if(isRoyalFlush()) { rank = RoyalFlush; } else if(isStraightFlush()) { rank = StraightFlush; } else if(fourKindPair()) { rank = FourOfaKind; } else if(isFullHouse()) { rank = FullHouse; } else if(sameSuit()) { rank = Flush; } else if(consecutive()) { rank = Straight; } else if(threeKindPair()) { rank = ThreeOfaKind; } else if(twoKindTwoPairs()) { rank = TwoPairs; } else if(twoKindOnePair()) { rank = OnePair; } else { rank = HighCard; } }
// TODO // Hand* Util::determineHandType(std::vector<Card*>& p_cards) { determineDuplicateCards(p_cards); Hand * newHand = nullptr; uint handType = HIGHEST_CARD; if (isRoyalFlush(p_cards)) { newHand = new NonRepeatedHand(ROYAL_FLUSH, p_cards); } else if (isStraightFlush(p_cards)) { newHand = new NonRepeatedHand(STRAIGHT_FLUSH, p_cards); } else if (isFourOfAKind()) { newHand = new RepeatedHand(FOUR_OF_A_KIND, p_cards, m_occurences, m_occurencesVector); } else if (isFullHouse()) { newHand = new RepeatedHand(FULL_HOUSE, p_cards, m_occurences, m_occurencesVector); } else if (isFlush(p_cards)) { newHand = new NonRepeatedHand(FLUSH, p_cards); } else if (isStraight(p_cards)) { newHand = new NonRepeatedHand(STRAIGHT, p_cards); } else if (isThreeOfAKind()) { newHand = new RepeatedHand(THREE_OF_A_KIND, p_cards, m_occurences, m_occurencesVector); } else if (isTwoPairs()) { newHand = new RepeatedHand(TWO_PAIRS, p_cards, m_occurences, m_occurencesVector); } else if (isOnePair()) { newHand = new RepeatedHand(ONE_PAIR, p_cards, m_occurences, m_occurencesVector); } else { newHand = new NonRepeatedHand(HIGHEST_CARD, p_cards); } m_occurences.clear(); m_occurencesVector.clear(); return newHand; }
uint32_t getHandValue(uint8_t * const hand) { orderHand(hand); if(isStraightFlush(hand)) return 8; if(isXOfKind(hand,4) ) return 7; if(isFullHouse(hand) ) return 6; if(isFlush(hand) ) return 5; if(isStraight(hand) ) return 4; if(isXOfKind(hand,3) ) return 3; if(isTwoPair(hand) ) return 2; if(isXOfKind(hand,2) ) return 1; return 0; }
int PokerHandEvaluator::evaluate(Hand hand){ //logic and some code taken from here: http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/10/pokerValue.html std::vector<Card*> cards = hand.getCards(); std::sort(cards.begin(), cards.end(), Compare()); if (isFlush(cards) && isStraight(cards)) return valueStraightFlush(cards); else if (is4s(cards)) return valueFourOfAKind(cards); else if (isFullHouse(cards)) return valueFullHouse(cards); else if (isFlush(cards)) return valueFlush(cards); else if (isStraight(cards)) return valueStraight(cards); else if (is3s(cards)) return valueSet(cards); else if (is22s(cards)) return valueTwoPairs(cards); else if (is2s(cards)) return valueOnePair(cards); else return valueHighCard(cards); // Lowest Poker hand; }
// Returns the roll's value for a given scoring choice const int DiceRoll::rollValue(const ChoiceAction choice) const { switch(choice) { case ACES: return sumIfEqual(1); case TWOS: return sumIfEqual(2); case THREES: return sumIfEqual(3); case FOURS: return sumIfEqual(4); case FIVES: return sumIfEqual(5); case SIXES: return sumIfEqual(6); case THREE_OF_A_KIND: if (isThreeOfAKind()) return sumAll(); return 0; case FOUR_OF_A_KIND: if (isFourOfAKind()) return sumAll(); return 0; case FULL_HOUSE: if (isFullHouse()) return 25; return 0; case SMALL_STRAIGHT: if (isSmallStraight()) return 30; return 0; case LARGE_STRAIGHT: if (isLargeStraight()) return 40; return 0; case YAHTZEE: if (isYahtzee()) return 50; return 0; case CHANCE: return sumAll(); case ROLL: assert(false); // Unscorable! } }
/* Adrian Hernandez */ void rankHand(Hand *hand){ cardrank tieBreaker; handrank hrank = HIGH_CARD; if ((tieBreaker = isStraightFlush(hand -> cards)) != NIL) { hrank = STRAIGHT_FLUSH; } else if ((tieBreaker = isFourKind(hand -> cards)) != NIL){ hrank = FOUR_KIND; } else if((tieBreaker = isFullHouse(hand -> cards)) != NIL){ hrank = FULL_HOUSE; } else if((tieBreaker = isFlush(hand -> cards)) != NIL){ hrank = FLUSH; } else if((tieBreaker = isStraight(hand -> cards)) != NIL){ hrank = STRAIGHT; } else if((tieBreaker = isThreeOfAKind(hand -> cards)) != NIL){ hrank = THREE_KIND; } else if((tieBreaker = isTwoPair(hand -> cards)) != NIL){ hrank = TWO_PAIR; } else if((tieBreaker = isOnePair(hand -> cards, NIL)) != NIL){ hrank = ONE_PAIR; } else { /* high card */ cardrank lowCard = (hand -> cards[0]) -> rank; cardrank highCard = (hand -> cards[POKER_HAND - 1]) -> rank; /* since ACE could be at the beginning */ tieBreaker = max(lowCard, highCard); } hand -> rank = hrank; hand -> tieBreaker = tieBreaker; }
int score(const std::vector<std::string>& vec) { if (isRoyalFlush(vec)) return 900; if (isStraightFlush(vec)) return 800 + getHighCard(vec); if (isFourCard(vec)) return 700 + getHighCard(vec, 4); if (isFullHouse(vec)) return 600 + getHighCard(vec, 3); if (isFlush(vec)) return 500 + getHighCard(vec); if (isStraight(vec)) return 400 + getHighCard(vec); if (isThreeCard(vec)) return 300 + getHighCard(vec, 3); if (isTwoPair(vec)) return 200 + getHighCard(vec, 2); if (isOnePair(vec)) return 100 + getHighCard(vec, 1); return getHighCard(vec); }
Comb::Combs Comb::getComb(const QStringList & cards) const { if (isStraightFlash(cards)) { return Comb::StraightFlash; } if (isCare(cards)) { return Comb::Care; } if (isFullHouse(cards)) { return Comb::FullHouse; } if (isFlash(cards)) { return Comb::Flash; } if (isStraight(cards)) { return Comb::Straight; } if (isThreeOfKind(cards)) { return Comb::ThreeOfKind; } if (isTwoPair(cards)) { return Comb::TwoPair; } if (isPair(cards)) { return Comb::Pair; } return Comb::Trash; }
PokerHand Hand::rank() const { if (isRoyalFlush()) return PokerHand::ROYAL_FLUSH; if (isStraightFlush()) return PokerHand::STRAIGHT_FLUSH; if (isFourOfAKind()) return PokerHand::FOUR_OF_A_KIND; if (isFullHouse()) return PokerHand::FULL_HOUSE; if (isFlush()) return PokerHand::FLUSH; if (isStraight()) return PokerHand::STRAIGHT; if (isThreeOfAKind()) return PokerHand::THREE_OF_A_KIND; if (isTwoPair()) return PokerHand::TWO_PAIR; if (isJacksOrBetter()) return PokerHand::JACKS_OR_BETTER; return PokerHand::NADA; }
int main() { char toReroll[DICE]; int sectionSelection; int categorySelection; int counter= 1; int upperUsed1 = 0; int upperUsed2 = 0; int upperUsed3 = 0; int upperUsed4 = 0; int upperUsed5 = 0; int upperUsed6 = 0; int lowerUsed1 = 0; int lowerUsed2 = 0; int lowerUsed3 = 0; int lowerUsed4 = 0; int lowerUsed5 = 0; int lowerUsed6 = 0; int lowerUsed7 = 0; srand(time(NULL)); int i; while (counter < 13) { //Must go 13 times to fill all categories printf("\: %i\n", counter); int rolls=1; //Variable to hold how many re-rolls a user gets for(i = 0; i < DICE; i++) { dice[i] = generateDice(); //Generates dice } printf("Your Roll: "); for(i = 0; i < DICE; i++){ printf("%i ", dice[i]); //Prints dice } printf("\n"); while(rolls < 3 ) { //Loop to re-roll dice if necessary printf("Which dice to reroll?\n"); scanf("%s", &toReroll); if(toReroll[0] == '0') { //Do not reroll any more dice if user enters '0' break; } else { for(i = 0; i < DICE; i++) { //printf("%c\n", toReroll[i]); if(toReroll[i] == NULL) { break; } int num = toReroll[i] - '0'; //Converts from char to int num -= 1; dice[num] = generateDice(); } int x; for(x = 0; x < DICE; x++){ printf("%i ", dice[x]); //Prints dice } printf("\n"); } rolls++; } printf("Place dice into:\n"); printf("1) Upper Section\n"); printf("2) Lower Section\n"); printf("Selection? "); scanf("%i", §ionSelection); printf("\n"); if(sectionSelection == 1) { //Place into Upper Section while(1) { printf("Place dice into:\n"); printf("1) Ones\n"); printf("2) Twos\n"); printf("3) Threes\n"); printf("4) Fours\n"); printf("5) Fives\n"); printf("6) Sixes\n"); scanf("%i", &categorySelection); printf("\n"); if(categorySelection == 1) { if(upperUsed1) { printf("Already used. Please pick again\n\n"); continue; } upper.ones = computeScore(categorySelection); score+= upper.ones; upperUsed1 = 1; break; } else if (categorySelection == 2) { if(upperUsed2) { printf("Already used. Please pick again\n\n"); continue; } upper.twos = computeScore(categorySelection); score+= upper.twos; upperUsed2 = 1; break; } else if (categorySelection == 3) { if(upperUsed3) { printf("Already used. Please pick again\n\n"); continue; } upper.threes = computeScore(categorySelection); score+= upper.threes; upperUsed3 = 1; break; } else if (categorySelection == 4) { if(upperUsed4) { printf("Already used. Please pick again\n\n"); continue; } upper.fours = computeScore(categorySelection); score+= upper.fours; upperUsed4 = 1; break; } else if (categorySelection == 5) { if(upperUsed5) { printf("Already used. Please pick again\n\n"); continue; } upper.fives = computeScore(categorySelection); score+= upper.fives; upperUsed5 = 1; break; } else if (categorySelection == 6) { if(upperUsed6) { printf("Already used. Please pick again\n\n"); continue; } upper.sixes = computeScore(categorySelection); score+= upper.sixes; upperUsed6 = 1; break; } } printScore(); printf("\n\n"); } else { //Place into Lower Section while(1) { char takeZero; printf("Place dice into:\n"); printf("1) Three of a Kind\n"); printf("2) Four of a Kind\n"); printf("3) Full House\n"); printf("4) Small Straight\n"); printf("5) Large Straight\n"); printf("6) Yahtzee\n"); printf("7) Chance\n"); scanf("%i", &categorySelection); printf("\n"); if(categorySelection == 1) { if(lowerUsed1) { printf("Already used. Please pick again\n\n"); continue; } if(!isThreeOfAKind()){ printf("You do not have three of a kind. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.threeOfAKind = 0; } else{ continue; } } else{ int sum = 0; for(i = 0; i < DICE; i++) { sum += dice[i]; } lower.threeOfAKind = sum; score+= lower.threeOfAKind; lowerUsed1 = 1; } } else if (categorySelection == 2) { if(lowerUsed2) { printf("Already used. Please pick again\n\n"); continue; } if(!isFourOfAKind()){ printf("You do not have four of a kind. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.fourOfAKind = 0; } else { continue; } } else{ int sum = 0; for(i = 0; i < DICE; i++) { sum += dice[i]; } lower.fourOfAKind = sum; score+= lower.fourOfAKind; lowerUsed2 = 1; } } else if (categorySelection == 3) { if(lowerUsed3) { printf("Already used. Please pick again\n\n"); continue; } if(!isFullHouse()) { printf("You do not have a full house. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.fullHouse = 0; } else { continue; } } else { lower.fullHouse = FULL_HOUSE; score += FULL_HOUSE; lowerUsed3 = 1; } } else if (categorySelection == 4) { if(lowerUsed4) { printf("Already used. Please pick again\n\n"); continue; } if(!isSmallStraight()) { printf("You do not have small straight. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.smallStraight = 0; } else { continue; } } else { lower.smallStraight = SMALL_STRAIGHT; score += SMALL_STRAIGHT; lowerUsed4 = 1; } } else if (categorySelection == 5) { if(lowerUsed5) { printf("Already used. Please pick again\n\n"); continue; } if(!isLargeStraight()) { printf("You do not have large straight. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.largeStraight = 0; } else { continue; } } else { lower.largeStraight = LARGE_STRAIGHT; score += LARGE_STRAIGHT; lowerUsed5 = 1; } } else if (categorySelection == 6) { if(lowerUsed6) { printf("Already used. Please pick again\n\n"); continue; } if(!isYahtzee()){ printf("You do not have yahtzee. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.threeOfAKind = 0; } else { continue; } } else { lower.yahtzee = YAHTZEE; score += YAHTZEE; lowerUsed6 = 1; } } else if(categorySelection == 7) { if(lowerUsed7) { printf("Already used. Please pick again\n\n"); continue; } int i; int tempScore = 0; for (i = 0; i < DICE; i++) { tempScore += dice[i]; } lower.chance = tempScore; score += tempScore; lowerUsed7 = 1; } printScore(); printf("\n"); break; } //End while } //End else counter++; } //End while if( (upper.ones + upper.twos + upper.threes + upper.fours + upper.fives + upper.sixes) > 63) { printf("35 Bonus points because your upper section totalled more than 63\n"); score+= 35; } addInZeros(); printf("Final Score\n"); printf("------------------------------------------\n"); printScore(); printf("------------------------------------------\n"); return 0; }
char* calculForceSymbolique(char* hand) { // création des forces symboliques char* forceSymbolique = new char[10]; if (isStraightFlush(hand) == 1) { sprintf(forceSymbolique, "9%c", hand[0]); return forceSymbolique; } if (isQuads(hand) == 1) { if (hand[0] == hand[2]) { sprintf(forceSymbolique, "8%c%c", hand[0], hand[8]); return forceSymbolique; } sprintf(forceSymbolique, "8%c%c", hand[2], hand[0]); return forceSymbolique; } if (isFullHouse(hand) == 1) { if (hand[0] == hand[4]) { sprintf(forceSymbolique, "7%c%c", hand[4], hand[8]); return forceSymbolique; } sprintf(forceSymbolique, "7%c%c", hand[4], hand[0]); return forceSymbolique; } if (isFlush(hand) == 1) { sprintf(forceSymbolique, "6%c%c%c%c%c", hand[0], hand[2], hand[4], hand[6], hand[8]); return forceSymbolique; } if (isStraight(hand) == 1) { sprintf(forceSymbolique, "5%c", hand[0]); return forceSymbolique; } if (isTrips(hand) == 1) { if (hand[0] == hand[4]) { sprintf(forceSymbolique, "4%c%c%c", hand[4], hand[6], hand[8]); return forceSymbolique; } sprintf(forceSymbolique, "4%c%c%c", hand[4], hand[0], hand[2]); return forceSymbolique; } if (isTwoPairs(hand) == 1) { if (hand[0] != hand[2]) { sprintf(forceSymbolique, "3%c%c%c", hand[2], hand[6], hand[0]); return forceSymbolique; } else if (hand[8] != hand[6]) { sprintf(forceSymbolique, "3%c%c%c", hand[0], hand[4], hand[8]); return forceSymbolique; } sprintf(forceSymbolique, "3%c%c%c", hand[0], hand[6], hand[4]); return forceSymbolique; } if (isSinglePair(hand) == 1) { if (hand[0] == hand[2]) { sprintf(forceSymbolique, "2%c%c%c%c", hand[0], hand[4], hand[6], hand[8]); return forceSymbolique; } else if (hand[2] == hand[4]) { sprintf(forceSymbolique, "2%c%c%c%c", hand[2], hand[0], hand[6], hand[8]); return forceSymbolique; } else if (hand[4] == hand[6]) { sprintf(forceSymbolique, "2%c%c%c%c", hand[4], hand[0], hand[2], hand[8]); return forceSymbolique; } sprintf(forceSymbolique, "2%c%c%c%c", hand[6], hand[0], hand[2], hand[4]); return forceSymbolique; } sprintf(forceSymbolique, "1%c%c%c%c%c", hand[0], hand[2], hand[4], hand[6], hand[8]); /*forceSymbolique[0]='1'; forceSymbolique[1]=hand[0]; forceSymbolique[2]=hand[2]; forceSymbolique[3]=hand[4]; forceSymbolique[4]=hand[6]; forceSymbolique[5]=hand[8]; forceSymbolique[6]='\0';*/ return forceSymbolique; }