Exemple #1
0
/**************************************
Determine whether a player has a Straight
Flush. A Straight Flush is any straight with
all five cards of the same suit. -Alicia
**************************************/
int isStraightFlush(struct player gamer, int numberOfCards)
{
    if (isStraight(gamer, numberOfCards) && isFlush(gamer, numberOfCards))
        return STRAIGHT_FLUSH;

    else
        return NONE;
}
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;


}
Exemple #3
0
/* Adrian Hernandez */
cardrank isStraightFlush(Card *cards[]){
    
    cardrank result           = NIL;
    cardrank isStraightResult = isStraight(cards);
    cardrank isFlushResult    = isFlush(cards);
    
    if ((isStraightResult != NIL) && (isFlushResult != NIL)) {
        result = isStraightResult;
    }
    return result;
}
Exemple #4
0
// 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;
}
Exemple #5
0
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;
}
Exemple #6
0
/* 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;
}
Exemple #7
0
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);
}
HandType PokerHandEvaluator::evaluate(Hand hand) {
    cards = hand.getCards();
    if (isFlush()) {
        return FLUSH;
    }
    if (hasFourOfKind() != NORANK) {
        return FOUROFAKIND;
    }
    if (hasTriple() != NORANK && pairCount() >= 2) {
        return HOUSE;
    }
    if (hasTriple() != NORANK) {
        return THREEOFAKIND;
    }
    if (pairCount() == 2) {
        return TWOPAIR;
    }
    if (pairCount() == 1) {
        return ONEPAIR;
    }


    return HIGHCARD;
}
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;
}
bool Hand::isStraightFlush() const
{
    return (isStraight() && isFlush());
}
Exemple #11
0
bool isStraightFlush(const std::vector<std::string>& vec)
{
	if (isStraight(vec) && isFlush(vec))
		return true;
	return false;
}
Exemple #12
0
void Poker::getCardType(std::vector<CCard> &mVecSortCards, CardType &ct)
{
	if (mVecSortCards.size() != 5)
	{
		return;
	}
	ct.clear();
	bool isflush = false;
	bool isstraight = false;
	isflush = isFlush(mVecSortCards);
	isstraight = isStraight(mVecSortCards);
	UInt8 mFirst = 0;
	UInt8 mSecond = 0;
	UInt8 mThird = 0;
	UInt8 mFourth = 0;
	UInt8 mScanTable[16];
	UInt8 keyvalue = 0;
	UInt8 type = 0;
	memset(mScanTable, 0, sizeof(mScanTable));
	for (size_t i = 0; i < mVecSortCards.size(); ++i)
	{
		if (mVecSortCards[i].m_nValue >= 3 && mVecSortCards[i].m_nValue <= 15)
		{
			mScanTable[mVecSortCards[i].m_nValue]++;
		}
	}

	for (int i = 2; i < 14; ++i)
	{
		if (mScanTable[i] == 1)
			++mFirst;
		else if (mScanTable[i] == 2)
			++mSecond;
		else if (mScanTable[i] == 3)
			++mThird;
		else if (mScanTable[i] == 4)
			++mFourth;
	}

	for (int i = 2; i < 14; ++i)
	{
		if (mScanTable[i] == 1)
			keyvalue = i;
		else if (mScanTable[i] == 2)
			++mSecond;
		else if (mScanTable[i] == 3)
			++mThird;
		else if (mScanTable[i] == 4)
			++mFourth;
	}

	if (mVecSortCards[0].m_nValue == 14 && isflush && isstraight)
	{
		type = 10;
		keyvalue = 14;
		return;
	}
	else if (mVecSortCards[0].m_nValue != 14 && isflush && isstraight)
	{
		type = 9;
		keyvalue = mVecSortCards[0].m_nValue;
		return;
	}
	else if(mFourth == 1 && mFirst == 1)
	{
		type = 8;
	}
	else if (mThird == 1 && mSecond == 1)
	{
		type = 7;
	}
	else if (isflush)
	{
		type = 6;
	}
	else if (isstraight)
	{
		type = 5;
	}
	else if (mThird == 1 && mFirst == 2)
	{
		type = 4;
	}
	else if (mSecond == 2 && mFirst == 1)
	{
		type = 3;
	}
	else if (mSecond == 1 && mFirst == 3)
	{
		type = 2;
	}
	else if (mFirst == 5)
	{
		type = 1;
	}
	type = 0;

	for (int i = 2; i < 14; ++i)
	{
		if (mScanTable[i] == 1 && type == 1)
		{
			keyvalue = i;
		}
		else if (mScanTable[i] == 2 && (type == 2 || type == 3) )
		{
			keyvalue = i;
		}
		else if (mScanTable[i] == 3 && (type == 4 || type == 7))
		{
			keyvalue = i;
			break;
		}
		else if (mScanTable[i] == 4)
		{
			keyvalue = i;
		}
	}
}
Exemple #13
0
int isStraightFlush(char* hand) { // test de la Quinte Flush
	if (isStraight(hand) == 1 && isFlush(hand) == 1)
		return 1;
	return 0;
}
Exemple #14
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;
}
void evaluateHand (Card *hand, int *cardRankCount, int* handScore) {
	int flush, straight;
	int quad[1] = {0}, triple[1] = {0}, pair[2] = {0}, single[HAND_SIZE] = {0};
	
	flush = isFlush (hand);
	straight = isStraight (cardRankCount);
	getNumNOfAKind (cardRankCount, 4, quad);
	getNumNOfAKind (cardRankCount, 3, triple);
	getNumNOfAKind (cardRankCount, 2, pair);
	getNumNOfAKind (cardRankCount, 1, single);
	if (straight == 10 && flush) {
		handScore[0] = ROYAL_FLUSH;
		return;
	}
	else if (straight != 0 && flush) {
		handScore[0] = STRAIGHT_FLUSH;
		handScore[1] = straight;
		return;
	} //{8, 9} represents 9,10,J,Q,K
	else if (quad[0] != 0) {
		handScore[0] = FOUR_OF_A_KIND;
		handScore[1] = quad[0];
		handScore[2] = single[0];
		return;
	} //{7, E, 2} represents A,A,A,A,2
	else if (triple[0] != 0 && pair[0] != 0) {
		handScore[0] = FULL_HOUSE;
		handScore[1] = triple[0];
		handScore[2] = pair[0];
		return;
	} //{6, E, D} represents A,A,A,K,K
	else if (flush) {
		handScore[0] = FLUSH;
		for (int i = 1; i < 1 + HAND_SIZE; i++) handScore[i] = single[i];
		return;
	} //{5, E, 6, 5, 4, 3} represents A,3,4,5,6
	else if (straight) {
		handScore[0] = STRAIGHT;
		handScore[1] = straight;
		return;
	} //{4, 2} represents 2,3,4,5,6
	else if (triple[0] != 0) {
		handScore[0] = THREE_OF_A_KIND;
		handScore[1] = triple[0];
		for (int i = 0; i < 2; i++) handScore[i + 2] = single[i];
		return;
	} //{3, E, 7, 6} represents A,A,A,7,6
	else if (pair[0] != 0 && pair[1] != 0) {
		handScore[0] = TWO_PAIR;
		for (int i = 0; i < 2; i++) handScore[i + 1] = pair[i];
		handScore[3] = single[0];
		return;
	} //{2, E, D, 6} represents A,A,K,K,6
	else if (pair[0] != 0) {
		handScore[0] = ONE_PAIR;
		handScore[1] = pair[0];
		for (int i = 0; i < 3; i++) handScore[i + 2] = single[i];
		return;
	} //{1, E, 6, 5, 4} represents A,A,4,5,6
	else {
		handScore[0] = BUST;
		for (int i = 0; i < HAND_SIZE; i++) handScore[i + 1] = single[i];
		return;
	} //{0, E, 6, 5, 4, 3} represents A,3,4,5,6
}
Exemple #16
0
uint8_t  isStraightFlush(uint8_t * const hand) {
    return isFlush(hand) && isStraight(hand);
}