Exemplo n.º 1
0
// Ex. 7
// Evaluates hand
int evaluate_hand(card* hand) {
	sort_hand(hand);
	int straight_flag = is_straight(hand);
	if(is_same_suit(hand)) {
		if((hand[0].value == 8) && (straight_flag)) return 9;	// If the 1st card is Ten and the cards form a straight, return 9 (Royal flush)
		if(straight_flag) return 8;								// If the cards form a straight, return 8 (Straight flush)
		else return 5;											// Otherwise, return 5 (Flush)
	}
	else if(is_four_of_a_kind(hand)) return 7;
	else if(is_full_house(hand)) return 6;
	else if(straight_flag) return 4;
	else if(is_three_of_a_kind(hand)) return 3;
	else if(is_two_pairs(hand)) return 2;
	else if(has_pair(hand)) return 1;
	return 0;													// If none of these evaluations holds, return 0 (Bust)
}
Exemplo n.º 2
0
void Evaluator::determine_strength(HandStrength *strength)
{
    // sort cards descending
    std::sort(all_cards.begin(), all_cards.end(), Card::greater);

    // clear combination cards and kicker_cards
    strength->clear_combination_cards();
    strength->clear_kicker_cards();

    // test for all combinations
    bool isFlush;
    if ((isFlush = is_flush(strength)) &&
        is_straight(strength,
                    strength->get_combination_cards()->front()->get_suit())) {
        strength->set_combination(HandStrength::STRAIGHT_FLUSH);
        // check royal flush
        if (strength->get_combination_cards()->front()->get_face() == Card::ACE) {
            strength->set_combination(HandStrength::ROYAL_FLUSH);
        }
    } else if (is_X_of_a_kind(FOUR_OF_A_KIND_SIZE, strength)) {
        strength->set_combination(HandStrength::FOUR_OF_A_KIND);
    } else if (is_full_house(strength)) {
        strength->set_combination(HandStrength::FULL_HOUSE);
    } else if (isFlush) {
        strength->set_combination(HandStrength::FLUSH);
    } else if (is_straight(strength)) {
        strength->set_combination(HandStrength:: STRAIGHT);
    } else if (is_X_of_a_kind(THREE_OF_A_KIND_SIZE, strength)) {
        strength->set_combination(HandStrength::TREE_OF_A_KIND);
    } else if (is_two_pairs(strength)) {
        strength->set_combination(HandStrength::TWO_PAIRS);
    } else if (is_X_of_a_kind(PAIR_SIZE, strength)) {
        strength->set_combination(HandStrength::PAIR);
    } else {
        strength->set_combination(HandStrength::HIGH_CARD);

        strength->clear_combination_cards();
        strength->add_to_combination_cards(all_cards.front());

        strength->clear_kicker_cards();
        for (card_it card = all_cards.begin() + 1;
             card != all_cards.end() && strength->get_kicker_cards()->size() <
             HandStrength::KICKER_CARDS_SIZE - 1; ++card) {
            strength->add_to_kicker_cards(*card);
        }
    }
}