static void constructorTest(){
    AI ar = AI("Arun", 5);
	
    Hand h;
    h.add(5);//initializing hardcoded hand
    h.add(4);
    h.add(0);
    h.add(1);
    h.add(7);
    int tab[4];//initializing hardcoded table
    tab[0] = 1;
    tab[1] = 4;
    tab[2] = 6;
    tab[3] = 9;
    std::vector<int> discPile[4];//Initialzing one of the discard piles.
    discPile[0].push_back(4);
    discPile[0].push_back(2);
    discPile[0].push_back(1);
    discPile[0].push_back(7);
    discPile[0].push_back(3);
    GameTree *nw = new GameTree(h, 5, tab, -1, 0, 0, discPile, nullptr, -1, -1);
    assert(nw->thand == h);
    assert(nw->StockPileTop == 5);
    assert(nw->table[0] == tab[0]);
    assert(nw->discPile[0] == discPile[0]);
    assert(nw->parent == nullptr);
  }
Exemple #2
0
TEST(Hand, add)
{
    Hand hand;
    EXPECT_EQ(0, hand.length());
    hand.add(Card(14, SuitSpade));
    hand.add(Card(2, SuitSpade));
    EXPECT_EQ(2, hand.length());
}
Exemple #3
0
TEST(Hand, isFlush_False)
{
    // 5H 5H 5H 6H KH
    Hand hand;
    hand.add(Card(5, SuitHeart));
    hand.add(Card(5, SuitHeart));
    hand.add(Card(5, SuitHeart));
    hand.add(Card(6, SuitDiamond));
    hand.add(Card(13, SuitHeart));
    
    EXPECT_FALSE(hand.isFlush());
}
Exemple #4
0
TEST(Hand, isStraight_False)
{
    // 3C 4H 5S 6H 7D
    Hand hand;
    hand.add(Card(3, SuitClub));
    hand.add(Card(3, SuitHeart));
    hand.add(Card(4, SuitSpade));
    hand.add(Card(5, SuitHeart));
    hand.add(Card(6, SuitDiamond));
    
    EXPECT_FALSE(hand.isStraight());
}
Exemple #5
0
TEST(Hand, isStraight_False2)
{
    // 3C 4H 7S 8H 9D
    Hand hand;
    hand.add(Card(3, SuitClub));
    hand.add(Card(4, SuitHeart));
    hand.add(Card(7, SuitSpade));
    hand.add(Card(8, SuitHeart));
    hand.add(Card(9, SuitDiamond));
    
    EXPECT_FALSE(hand.isStraight());
}
Exemple #6
0
void GeneralPlayer::getFlushRank(Hand& table, GeneralPlayer::HandRating& handRating, const Card::suit suit)
{
	Hand showDownHand;
	showDownHand.add(m_cards);
	showDownHand.add(table.getHand());
	vector<Card*> showDownCards = showDownHand.getHand();
	for (int i = 12, j = 0; j < 5; ++j)
	{
		if (showDownCards[i]->getSuit() == suit)
			handRating.kickerRank[j] = i;
	}
}
Exemple #7
0
TEST(Hand, isFlush_True)
{
    // 5H 5H 5H 6H KH
    Hand hand;
    hand.add(Card(5, SuitHeart));
    hand.add(Card(5, SuitHeart));
    hand.add(Card(5, SuitHeart));
    hand.add(Card(6, SuitHeart));
    hand.add(Card(13, SuitHeart));
    
    EXPECT_TRUE(hand.isFlush());
}
Exemple #8
0
TEST(Hand, longestSameCardsLength_1)
{
    // 3C 7H AS TH 9D
    Hand hand;
    hand.add(Card(3, SuitClub));
    hand.add(Card(7, SuitHeart));
    hand.add(Card(14, SuitSpade));
    hand.add(Card(10, SuitHeart));
    hand.add(Card(9, SuitDiamond));
    
    int cardNum;
    int len = hand.longestSameCardsLength(cardNum);
    
    EXPECT_EQ(1, len);
    EXPECT_EQ(14, cardNum);
}
Exemple #9
0
TEST(Hand, computeRank_straight)
{
    // 3H 4C 5S 6D 7D
    Hand hand;
    hand.add(Card(3, SuitHeart));
    hand.add(Card(4, SuitClub));
    hand.add(Card(5, SuitSpade));
    hand.add(Card(6, SuitDiamond));
    hand.add(Card(7, SuitDiamond));
    
    hand.computeRank();
    EXPECT_EQ(RankStraight, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(1,  pts.size());
    EXPECT_EQ(7,  pts[0]);
}
Exemple #10
0
TEST(Hand, computeRank_straightFlush)
{
    // 3C 4C 5C 6C 7C
    Hand hand;
    hand.add(Card(3, SuitClub));
    hand.add(Card(4, SuitClub));
    hand.add(Card(5, SuitClub));
    hand.add(Card(6, SuitClub));
    hand.add(Card(7, SuitClub));
    
    hand.computeRank();
    EXPECT_EQ(RankStraightFlush, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(1,  pts.size());
    EXPECT_EQ(7,  pts[0]);
}
Exemple #11
0
TEST(Hand, computeRank_fullHouse)
{
    // 5H 5C 5D 9H 9S
    Hand hand;
    hand.add(Card(5, SuitHeart));
    hand.add(Card(5, SuitClub));
    hand.add(Card(5, SuitDiamond));
    hand.add(Card(9, SuitHeart));
    hand.add(Card(9, SuitSpade));
    
    hand.computeRank();
    EXPECT_EQ(RankFullHouse, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(2,  pts.size());
    EXPECT_EQ(5,  pts[0]);
    EXPECT_EQ(9,  pts[1]);
}
Exemple #12
0
TEST(Hand, computeRank_fourOfaKind)
{
    // 5H 5C 5S 5D KD
    Hand hand;
    hand.add(Card(5,  SuitHeart));
    hand.add(Card(5,  SuitClub));
    hand.add(Card(5,  SuitSpade));
    hand.add(Card(5,  SuitDiamond));
    hand.add(Card(13, SuitDiamond));
    
    hand.computeRank();
    EXPECT_EQ(RankFourOfaKind, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(2,  pts.size());
    EXPECT_EQ(5,  pts[0]);
    EXPECT_EQ(13, pts[1]);
}
Exemple #13
0
TEST(Hand, computeRank_twoPairs)
{
    // 5H 5C 6S 6D KD
    Hand hand;
    hand.add(Card(5,  SuitHeart));
    hand.add(Card(5,  SuitClub));
    hand.add(Card(6,  SuitSpade));
    hand.add(Card(6,  SuitDiamond));
    hand.add(Card(13, SuitDiamond));
    
    hand.computeRank();
    EXPECT_EQ(RankTwoPairs, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(3,  pts.size());
    EXPECT_EQ(6,  pts[0]);
    EXPECT_EQ(5,  pts[1]);
    EXPECT_EQ(13, pts[2]);
}
Exemple #14
0
TEST(Hand, computeRank_onePair)
{
    // 5H 5C 6S 7S KD
    Hand hand;
    hand.add(Card(5,  SuitHeart));
    hand.add(Card(5,  SuitClub));
    hand.add(Card(6,  SuitSpade));
    hand.add(Card(7,  SuitSpade));
    hand.add(Card(13, SuitDiamond));
    
    hand.computeRank();
    EXPECT_EQ(RankOnePair, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(4,  pts.size());
    EXPECT_EQ(5,  pts[0]);
    EXPECT_EQ(13, pts[1]);
    EXPECT_EQ(7,  pts[2]);
    EXPECT_EQ(6,  pts[3]);
}
Exemple #15
0
TEST(Hand, computeRank_highcard)
{
    // 7S 5S 9S JD KD
    Hand hand;
    hand.add(Card(7, SuitSpade));
    hand.add(Card(5, SuitSpade));
    hand.add(Card(9, SuitSpade));
    hand.add(Card(11, SuitDiamond));
    hand.add(Card(13, SuitDiamond));
    
    hand.computeRank();
    EXPECT_EQ(RankHighCard, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(5,  pts.size());
    EXPECT_EQ(13, pts[0]);
    EXPECT_EQ(11, pts[1]);
    EXPECT_EQ(9,  pts[2]);
    EXPECT_EQ(7,  pts[3]);
    EXPECT_EQ(5,  pts[4]);
}
Exemple #16
0
TEST(Hand, computeRank_flush)
{
    // 5H 5H 5H 6H KH
    Hand hand;
    hand.add(Card(5, SuitHeart));
    hand.add(Card(5, SuitHeart));
    hand.add(Card(5, SuitHeart));
    hand.add(Card(6, SuitHeart));
    hand.add(Card(13, SuitHeart));
    
    hand.computeRank();
    EXPECT_EQ(RankFlush, hand.rank());
    
    std::vector<int> pts;
    hand.points(pts);
    ASSERT_EQ(5,  pts.size());
    EXPECT_EQ(13, pts[0]);
    EXPECT_EQ(6,  pts[1]);
    EXPECT_EQ(5,  pts[2]);
    EXPECT_EQ(5,  pts[3]);
    EXPECT_EQ(5,  pts[4]);
}
/* Deck function to move a card from the back of the deck to a hand.*/
void Deck::deal(Hand &cards)
{
	this->cards.back().flip();
	cards.add(&this->cards.back());
	this->cards.pop_back();
}
Exemple #18
0
int main()
{
  int points = 100;
  char option;
  Hand playerHand;
  Hand dealerHand;
  Deck deck;
  bool handover = false;

  cout << "Welcome to Black Jack!" << endl;
  cout << "======================" << endl << endl;
  do {
    cout << "Current points: " << points << endl << endl;
    cout << "Would you like to: (d)eal or (q)uit? ";
    cin >> option;
      while (option != 'q' && option != 'Q' && option != 'd' && option != 'D')
      {
        cout << "Invalid option. Would you like to: (d)eal or (q)uit? ";
        cin >> option;
      }
      if (option == 'q' || option == 'Q')
      {
        cout << "Game over.  Total points: " << points << endl << endl;
        return 0;
      }
    cout << "Shuffling deck..." << endl;

    srand(time(NULL));
    int shuffleAmt = rand() % 100;
    deck.shuffle(shuffleAmt);

    cout << "Dealing cards..." << endl << endl;
    Hand playerHand;
    Hand dealerHand;
    playerHand.add(deck.deal());
    dealerHand.add(deck.deal());
    playerHand.add(deck.deal());
    dealerHand.add(deck.deal());

    cout << "Dealer currently shows: ";
    dealerHand.outputDealer(cout);
    cout << endl;
    cout << "Your hand: " << playerHand << endl << endl;
    do
    {
      handover = false;
      cout << "Would you like to: (h)it or (s)tand? ";
      cin >> option;
      while (option != 'h' && option != 'H' && option != 's' && option != 'S')
      {
        cout << "Invalid option.  Would you like to: (h)it or (s)tand? ";
        cin >> option;
      }
      if (option == 'h' || option == 'H')
      {
        if (playerHand.size() < 5)
        {
          playerHand.add(deck.deal());
          cout << "Your hand: " << playerHand << endl << endl;
        }
        else
        {
          cout << "No more than 5 cards per hand allowed!" << endl;
        }
      }
    } while (option != 's' && option != 'S' && playerHand.size() < 5 && playerHand.value() <= 21);


    if (playerHand.value() > 21)
    {
      cout << "BUST!" << endl;
      points -= 10;
      handover = true;
    }
    cout << endl << "Dealer's hand: " << dealerHand << endl;

    if (!handover)
    {
      while (dealerHand.value() < 17 && dealerHand.size() < 5 )
      {
        dealerHand.add(deck.deal());
        cout << "Dealer hits on hand value < 17." << endl;
        cout << "Dealer's hand: " << dealerHand << endl;
      }
      if (dealerHand.value() > 21)
      {
        cout << "Dealer busts, you win!" << endl;
        points += 10;
      }
      else
      {
        cout << endl << "YOUR FINAL HAND: " << playerHand  << " TOTAL: " << playerHand.value() << endl;
        cout << "DEALER'S FINAL HAND: " << dealerHand << " TOTAL: " << dealerHand.value() << endl;
        if (dealerHand.isLess(playerHand))
        {
          cout << "You win!" << endl;
          points += 10;
        }
        else if (playerHand.isLess(dealerHand))
        {
          cout << "You lose!" << endl;
          points -= 10;
        }
        else if (playerHand.isEqual(dealerHand))
        {
          cout << "Tie!" << endl;
        }
      }
    }
    if (deck.size() < 20)
    {
      deck.reset();
    }
  } while (points > 0);
  return 0;
}