int main() {
	
	Card::Rank r = static_cast<Card::Rank>(0);
	Card::Suit s = static_cast<Card::Suit>(0);

	Player *player_ptr = player_factory("counting");
  	
	Card card = Card(r, s);
	Card dealerCard = card;
	Hand playerHand;
	playerHand.add_card(card);
	
	
	
	assert((*player_ptr).draw(dealerCard, playerHand));
	
	r = static_cast<Card::Rank>(7);
	
	card = Card(r, s);
	playerHand.add_card(card);

	assert((*player_ptr).draw(dealerCard, playerHand));

	return 0;
}
TEST(HandTest, testTwoPair) {
    for (uint16_t v1 : kValues) {
        for (uint16_t v2 : kValues) {
            if (v1 == v2)
                continue;
            for (uint16_t v3 : kValues) {
                if (v1 == v3 || v2 == v3)
                    continue;
                Hand h;
                Card c1{v1, kHearts};
                Card c2{v1, kClubs};
                Card c3{v2, kDiamonds};
                Card c4{v2, kSpades};
                Card c5{v3, kClubs};

                h.add_card(c1);
                h.add_card(c2);
                h.add_card(c3);
                h.add_card(c4);
                h.add_card(c5);

                EXPECT_GE(h.rank(), 1l << 58);
                EXPECT_LT(h.rank(), 1l << 59);
            }
        }
    }
}
Example #3
0
Card Hand::deal_card_from_bottom(Hand &h)
{
	// "bottom" is the beginning of the deck
	Card c = hand.remove_from_head();
	h.add_card(c);
	return c;
}
Example #4
0
int main()
{
	const char* counting = "counting";
	Player *cplayer = player_factory(counting);

	Hand chand;
	Hand chand1;
	Hand chand2;

	//I added this comment line

	Card c = Card(Card::ACE, Card::SPADES);
	Card d = Card(Card::FIVE, Card::CLUBS);

	Card f = Card(Card::SIX, Card::CLUBS);

	Card g = Card(Card::TWO, Card::CLUBS);

	Card e = Card(Card::FOUR, Card::SPADES);

	chand.add_card(c);
	chand.add_card(d);

	chand1.add_card(c);
	chand1.add_card(f);

	chand2.add_card(c);
	chand2.add_card(g);

	assert(cplayer->draw(e, chand) == true);
	assert(cplayer->draw(e, chand1) == true);
	assert(cplayer->draw(e, chand2) == true);

return 0;
}
TEST(HandTest, testLowStraightFlush) {
    Hand h;
    Card c1{kTwo, kHearts};
    Card c2{kThree, kHearts};
    Card c3{kFour, kHearts};
    Card c4{kFive, kHearts};
    Card c5{kSix, kHearts};

    h.add_card(c1);
    h.add_card(c2);
    h.add_card(c3);
    h.add_card(c4);
    h.add_card(c5);

    EXPECT_EQ(h.rank(), 8);
}
Example #6
0
Card Hand::deal_card_from_top(Hand &h)
{
	// "top" is the end of the array
	Card c = hand.remove_from_tail();
	h.add_card(c);
	return c;
}
TEST(HandTest, testFlush) {
    Hand h;
    Card c1{kTwo, kHearts};
    Card c2{kThree, kHearts};
    Card c3{kFour, kHearts};
    Card c4{kFive, kHearts};
    Card c5{kSeven, kHearts};

    h.add_card(c1);
    h.add_card(c2);
    h.add_card(c3);
    h.add_card(c4);
    h.add_card(c5);

    EXPECT_GE(h.rank(), 1l << 55);
    EXPECT_LT(h.rank(), 1l << 56);
}
TEST(HandTest, testWheelStraightFlush) {
    Hand h;
    Card c1{kTwo, kHearts};
    Card c2{kThree, kHearts};
    Card c3{kFour, kHearts};
    Card c4{kFive, kHearts};
    Card c5{kAce, kHearts};

    h.add_card(c1);
    h.add_card(c2);
    h.add_card(c3);
    h.add_card(c4);
    h.add_card(c5);

    EXPECT_LT(h.rank(), 10);
    EXPECT_EQ(h.rank(), 9);
}
TEST(HandTest, testWheelStraight) {
    Hand h;
    Card c1{kTwo, kDiamonds};
    Card c2{kThree, kHearts};
    Card c3{kFour, kHearts};
    Card c4{kFive, kHearts};
    Card c5{kAce, kHearts};

    h.add_card(c1);
    h.add_card(c2);
    h.add_card(c3);
    h.add_card(c4);
    h.add_card(c5);

    EXPECT_GE(h.rank(), 1l << 56);
    EXPECT_LT(h.rank(), 1l << 57);
}
TEST(HandTest, testHighCard) {
    Hand h;
    Card c1{kTwo, kHearts};
    Card c2{kKing, kClubs};
    Card c3{kAce, kDiamonds};
    Card c4{kThree, kSpades};
    Card c5{kSeven, kClubs};

    h.add_card(c1);
    h.add_card(c2);
    h.add_card(c3);
    h.add_card(c4);
    h.add_card(c5);

    EXPECT_GE(h.rank(), 1l << 60);
    EXPECT_LT(h.rank(), 1l << 61);
}
TEST(HandTest, testHighStraightFlush) {
    Hand h;
    Card c1{kAce, kHearts};
    Card c2{kKing, kHearts};
    Card c3{kQueen, kHearts};
    Card c4{kJack, kHearts};
    Card c5{kTen, kHearts};

    h.add_card(c1);
    h.add_card(c2);
    h.add_card(c3);
    h.add_card(c4);
    h.add_card(c5);

    EXPECT_LT(h.rank(), 10);
    EXPECT_EQ(h.rank(), 0);
}
TEST(HandTest, testAddCard) {
    Hand h;
    Deck d;

    d.shuffle();

    for (int i = 0; i < 5; i++) {
        h.add_card(d.take());
        EXPECT_EQ(i + 1, h.size());
    }
}
TEST(HandTest, testPair) {
    for (uint i = 0; i < kValues.size(); i++) {
        Hand h;
        Card c1{kValues[i], kHearts};
        Card c2{kValues[i], kDiamonds};

        Card c3{kValues[(i + 1) % kValues.size()], kSpades};
        Card c4{kValues[(i + 2) % kValues.size()], kSpades};
        Card c5{kValues[(i + 3) % kValues.size()], kSpades};

        h.add_card(c1);
        h.add_card(c2);
        h.add_card(c3);
        h.add_card(c4);
        h.add_card(c5);

        EXPECT_GE(h.rank(), 1l << 59);
        EXPECT_LT(h.rank(), 1l << 60);
    }
}
//choose best five cards
Hand TexasHoldEm::best_five(Player & player){
	Hand hand = player.getPlayerHand();

	vector<Hand>allhands;
	for (size_t i = 0; i < VALID_SEVEN_CARDSTUD_HAND_SIZE; i++){


		for (size_t j = i + 1; j < VALID_SEVEN_CARDSTUD_HAND_SIZE; j++){

			for (size_t k = j + 1; k < VALID_SEVEN_CARDSTUD_HAND_SIZE; k++){

				for (size_t m = k + 1; m < VALID_SEVEN_CARDSTUD_HAND_SIZE; m++){

					for (size_t n = m + 1; n < VALID_SEVEN_CARDSTUD_HAND_SIZE; n++){
						Hand temphand;
						temphand.add_card(hand[i]);
						temphand.add_card(hand[j]);
						temphand.add_card(hand[k]);
						temphand.add_card(hand[m]);
						temphand.add_card(hand[n]);
						vector<Card> temp_cards = temphand.getCards();
						sort(temp_cards.begin(), temp_cards.end());
						temphand.sethand(temp_cards);
						temphand.setHandRank();
						allhands.push_back(temphand);

					}
				}
			}

		}

	}


	sort(allhands.begin(), allhands.end(), poker_rank);

	return allhands[0];
}
//choose five five cards
Hand SevenCardStud::best_five(Player & player){
	Hand hand = player.getPlayerHand();

	vector<Hand>allhands;

	//generate all posible combinations
	for (size_t i = 0; i < VALID_SEVEN_CARDSTUD_HAND_SIZE; i++){
		for (size_t j = i + 1; j < VALID_SEVEN_CARDSTUD_HAND_SIZE; j++){
			for (size_t k = j + 1; k < VALID_SEVEN_CARDSTUD_HAND_SIZE; k++){
				for (size_t m = k + 1; m < VALID_SEVEN_CARDSTUD_HAND_SIZE; m++){
					for (size_t n = m + 1; n < VALID_SEVEN_CARDSTUD_HAND_SIZE; n++){
						Hand temphand;
						temphand.add_card(hand[i]);
						temphand.add_card(hand[j]);
						temphand.add_card(hand[k]);
						temphand.add_card(hand[m]);
						temphand.add_card(hand[n]);
						vector<Card> temp_cards = temphand.getCards();
						sort(temp_cards.begin(), temp_cards.end());
						temphand.sethand(temp_cards);
						temphand.setHandRank();
						allhands.push_back(temphand);

					}
				}
			}

		}

	}

	//sort combinations
	sort(allhands.begin(), allhands.end(), poker_rank);

	//choose the best one
	return allhands[0];
}
Example #16
0
int main()
{
	const char* counting = "counting";
	Player *cplayer = player_factory(counting);

	Hand chand;
	Card c = Card(Card::FIVE, Card::SPADES);
	Card d = Card(Card::SEVEN, Card::CLUBS);

	Card e = Card(Card::KING, Card::SPADES);
	Card f = Card(Card::TWO, Card::SPADES);
	Card g = Card(Card::THREE, Card::SPADES);
	Card h = Card(Card::SEVEN, Card::SPADES);
	Card i = Card(Card::EIGHT, Card::SPADES);
	Card j = Card(Card::NINE, Card::SPADES);
	Card k = Card(Card::TEN, Card::SPADES);
	Card l = Card(Card::JACK, Card::SPADES);
	Card m = Card(Card::QUEEN, Card::SPADES);
	Card n = Card(Card::ACE, Card::SPADES);

	chand.add_card(c);
	chand.add_card(d);

	assert(cplayer->draw(e, chand) == true);
	assert(cplayer->draw(f, chand) == true);
	assert(cplayer->draw(g, chand) == true);
	assert(cplayer->draw(h, chand) == true);
	assert(cplayer->draw(i, chand) == true);
	assert(cplayer->draw(j, chand) == true);
	assert(cplayer->draw(k, chand) == true);
	assert(cplayer->draw(l, chand) == true);
	assert(cplayer->draw(m, chand) == true);
	assert(cplayer->draw(n, chand) == true);

return 0;
}
Example #17
0
int main(int argc, const char * argv[])
{
    Deck deck;
    Player *player = player_factory(argv[3]);
    Hand hand;
    
    cout << "Shuffling the deck\n";
    for (int counter = 0; counter < 7; counter++) {
        int num = get_cut();
        cout << "cut at " << num << endl;
        deck.shuffle(num);
        player->shuffled();
    }
    
    int minBet = 5;
    int bankroll = atoi(argv[1]);
    int totalHands = atoi(argv[2]);
    int handsPlayed = 1;
    
    while ((bankroll >= minBet) & (handsPlayed <= totalHands)) {
        cout << "Hand " << handsPlayed << " bankroll " << bankroll << endl;
        if (deck.cards_remaining() < 20) {
            int cutNum = get_cut();
            cout << "cut at " << cutNum << endl;
            deck.shuffle(cutNum);
            player->shuffled();
        }
        
        
        int wager = player->bet(bankroll, minBet);
        cout << "Player bets " << wager << endl;

        Hand dealerHand;
        
        Card p1;
        Card p2;
        Card d1;
        Card d2;
        p1 = deck.deal();
        d1 = deck.deal();
        p2 = deck.deal();
        d2 = deck.deal();
        hand.add_card(p1);
        hand.add_card(p2);
        dealerHand.add_card(d1);
        dealerHand.add_card(d2);
        
        cout << "Player dealt " << p1 << endl;
        player->expose(p1);
        cout << "Dealer dealt " << d1 << endl;
        player->expose(d1);
        cout << "Player dealt " << p2 << endl;
        player->expose(p2);
        
        if (hand.hand_value() == 21) {
            bankroll += (3/2)*wager;
            cout << "Player dealt natural 21\n";
            handsPlayed++;
            hand.discard_all();
        } else {
        
        cout << "Player's total is " << hand.hand_value() << endl;
        while (player->draw(d1, hand)) {
            Card c1 = deck.deal();
            hand.add_card(c1);
            player->expose(c1);
            cout << "Player dealt " << c1 << endl;
            cout << "Player's total is " << hand.hand_value() << endl;
        }
        
        if ((hand.hand_value() > 21) & (!hand.hand_is_soft())) {
            cout << "Player busts!" << endl;
            bankroll -= wager;
            handsPlayed++;
            hand.discard_all();
        } else {
            cout << "Dealer's hole card is " << d2 << endl;
            player->expose(d2);
            
            while (dealerHand.hand_value() < 17) {
                Card c1 = deck.deal();
                dealerHand.add_card(c1);
                player->expose(c1);
                cout << "Dealer dealt " << c1 << endl;
            }
            cout << "Dealer's total is " << dealerHand.hand_value() << endl;
        
            if ((dealerHand.hand_value() > 21) & (!dealerHand.hand_is_soft())) {
                cout << "Dealer busts!" << endl;
                bankroll += wager;
                handsPlayed++;
                hand.discard_all();
            } else {
        
                if (dealerHand.hand_value() > hand.hand_value()) {
                    cout << "Dealer wins\n";
                    bankroll -= wager;
                    handsPlayed++;
                    hand.discard_all();
                } else if (dealerHand.hand_value() < hand.hand_value()) {
                    cout << "Player wins\n";
                    bankroll += wager;
                    handsPlayed++;
                    hand.discard_all();
                } else {
                    cout << "Push\n";
                    handsPlayed++;
                    hand.discard_all();
                }
            }
        }
    }
}
    
    cout << "Player has " << bankroll << " after " << handsPlayed-1 << " hands\n";
}
Example #18
0
int main (int argc, char *argv[])
{
	
	assert(argc == 4);
	int bankRoll = atoi(argv[1]);
	int maxHands = atoi(argv[2]);
	//bankRoll and max # of hands taken in from command line
	

	Player *player = player_factory(argv[3]);
	//type of player confirmed

	Deck deck;
	//Deck initialized

	int handsPlayed = maxHands;

	deckShuffle(&deck, player);
	(*player).shuffled();
	for (int i = 0; i < maxHands; i++)
	{
		if (bankRoll >= 5)
		{
			cout << "Hand " << (i+1) << " bankroll " << bankRoll << endl;

			if (deck.cards_remaining() < 20)
			{
				deckShuffle(&deck, player);
				(*player).shuffled();
			}

			int wager = (*player).bet(bankRoll, MIN_BET);
			cout << "Player bets " << wager << endl;

			Hand playerHand = Hand();
			Hand dealerHand = Hand();
			//hands initialized
			Card dealerUp;
			for (int i = 0; i < 3; i++)
			{
				Card nextCard = deck.deal();
				if (i == 1)
				{
					addUpCard("Dealer", &dealerHand, player, nextCard);
					dealerUp = nextCard;
				}
				else
				{
					addUpCard("Player", &playerHand, player, nextCard);
				}
			}
			//Deals all visible cards

			Card dealerDown = deck.deal();
			dealerHand.add_card(dealerDown);
			//dealer facedown card dealt

			if (playerHand.hand_value() == 21)
			{
				cout << "Player dealt natural 21\n";
				bankRoll += (3*wager)/2;
			}
			else
			{
				int total = playerHand.hand_value(); 
				while ((*player).draw(dealerUp, playerHand))
				{
					Card nextCard = deck.deal();
					addUpCard("Player", &playerHand, player, nextCard);
					total = playerHand.hand_value();
				}
				// draws cards
				cout << "Player's total is " << total << endl;
				if (total > 21)
				{
					cout << "Player busts\n";
					bankRoll -= wager;
				}
				else
				{
					(*player).expose(dealerDown);
					cout << "Dealer's hole card is " << dealerDown << endl;
					while (dealerHand.hand_value() < 17)
					{
						Card nextCard = deck.deal();
						addUpCard("Dealer", &dealerHand, player, nextCard);
						total = dealerHand.hand_value();
					}

					cout << "Dealer's total is " << total << endl;
					if (total > 21)
					{
						cout << "Dealer busts\n";
						bankRoll += wager;
					}
					else
					{
						int dealerTotal = dealerHand.hand_value();
						int playerTotal = playerHand.hand_value();

						if (dealerTotal > playerTotal)
						{
							cout << "Dealer wins\n";
							bankRoll -= wager;
						}
						else if (playerTotal > dealerTotal)
						{
							cout << "Player wins\n";
							bankRoll += wager;
						}
						else
						{
							cout << "Push\n";
						}
					}
					// prints result
				}
			}	
		}
	
		else
		{
			handsPlayed = i + 1;
			break;
		}
	}

	cout << "Player has " << bankRoll << " after " << handsPlayed << " hands\n";
	return 0;

	
}