예제 #1
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;
}
예제 #2
0
/* Adrian Hernandez */
cardrank isFullHouse(Card *cards[]){
    
    cardrank result = NIL;
    cardrank threeKindResult = isThreeOfAKind(cards);
    
    if (threeKindResult != NIL) {
        /* check if there are 2 matching cards of a different rank. */
        if (isOnePair(cards, threeKindResult) != NIL){
            result = threeKindResult;
        }
    }
    return result;
}
예제 #3
0
//Function that checks for two different pair of cards. Each pair is a pair of cards with the same rank.
cardrank isTwoPair(Card *pokerHand[])
{
    
    cardrank firstPair, secondPair, result;
    
    firstPair  = isOnePair(pokerHand, NIL);  //Checks for one pair first
    secondPair = NIL;
    
    if(firstPair != NIL)                      //If there is a first pair then it gets ignored to check for a second pair.
    {
        secondPair = isOnePair(pokerHand, firstPair);
    }
    
    if((firstPair == NIL || secondPair == NIL) || (firstPair == secondPair)) //Return NIL if there is only one pair or no pairs or if both pairs have same rank.
    {
        result = NIL;
    }
    else
    {
        result = max(firstPair,secondPair);                           //Returns the largest ranked pair for tiebreaking
    }
    
    return result;
}
예제 #4
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;
}
예제 #5
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);
}
예제 #6
0
/* Camilo Riviere */
cardrank isStraight(Card *hand[]){
    
    cardrank result = NIL;
    cardrank onePairTest = isOnePair(hand, NIL);

    /* check that there are not two cards with matching ranks */
    if (onePairTest == NIL) {
        
        cardrank first = hand[0] -> rank;
        cardrank second = hand[1] -> rank;
        cardrank last = hand[POKER_HAND - 1] -> rank;

        if ((last - first) == (POKER_HAND - 1)) {
            /* cards are in sequence */
            result = last;
        }
        else if ((first == ACE) && (last == KING) && ((last - second) == POKER_HAND - 2)){
            /* royal straight */
            result = ACE;
        }
    }
    return result;
}
예제 #7
0
bool Util::isFullHouse()
{
	return (isThreeOfAKind() && isOnePair());
}