Esempio n. 1
0
void PokerDriver::finalizeRound() {
    for (int i = 0; i < m_Players.size(); i++) {
        m_Players[i]->setMoneyInPot(0);

        if (m_Players[i]->getMoneyInPot() != 0)
            cout << "Get_Money_FAILURE" << endl;
    }

    m_PotMoney = 0;
    Hand *hand;
    for (int i = 0; i < m_Players.size(); i++) {
        m_Players[i]->setFolded(false);
        hand = m_Players[i]->getHand();

        if (hand->getCard(2) != NULL)
            cout << "Get_Card_SUCCESS" << endl;
        else
            cout << "FAILURE_5" << endl;

        for (int j = 0; j < 5; j++) {
            m_Deck.discardCard(hand->getCard(j));
            cout << "Discard_SUCCESS" << endl;
        }
    }
}
Esempio n. 2
0
// Cycles through the hand passed and sums
// values of the cards.
// As hands are initialised to have all jokers
// the jokers are not totaled up
int calculateHandValue(Hand myHand)
{
	int total = 0;
	for(int i = 0; i < 11; i++)
	{
		if(myHand.getCard(i).getCardDisplay() != 'X')
			total += myHand.getCard(i).getCardValue();
	}
	return total;
}
Esempio n. 3
0
bool Straight::isPokerPlayable(Hand& selection, Pile& playPile){
  Hand topHand = playPile.getTopHand();
  if(topHand.size() == '\0'){
    return true;
  }else if(topHand.size() != 5){
    return false;
  }
  //Highest ranking card at the top of the sequence wins
  if((selection.getCard(0)->getRank() > topHand.getCard(0)->getRank())){
    return true;
  }
}
Esempio n. 4
0
void computeWinner(Hand computerCards, Hand playerCards)
{
	// As computer wins when it has 21 reguardless
	// this case is first
	if(calculateHandValue(computerCards) == 21)
	{
		cout << "Computer wins with 21 hand!\n";
	}
	// If player has 21 and computer doesn't
	// they win
	else if(calculateHandValue(playerCards) == 21)
	{
		cout << "You win!\n"
			"Computer had:\n";
		// Display all cards in computers hand that aren't Jokers
		// This proves to the player no foul play
		for(int j = 0; j < 11; j++)
		{
			if(computerCards.getCard(j).getCardDisplay() != 'X')
				printCard(computerCards.getCard(j));
		}
	}
	// If computer hasn't busted and has a higher score than the player computer wins
	else if((calculateHandValue(computerCards) > calculateHandValue(playerCards)) && (calculateHandValue(computerCards) < 21))
	{
		cout << "Computer wins! With: \n";
		// Display all cards in computers hand that aren't Jokers
		// This proves to the player no foul play
		for(int j = 0; j < 11; j++)
		{
			if(computerCards.getCard(j).getCardDisplay() != 'X')
				printCard(computerCards.getCard(j));
		}
		cout << "Computer cards value is: " << calculateHandValue(computerCards) << endl;
	}
	// If player hasn't busted and has a higher score than computer
	else if((calculateHandValue(computerCards) < calculateHandValue(playerCards)) && calculateHandValue(playerCards) < 21)
	{
		cout << "You win!\n"
			"Computer had:\n";
		// Display all cards in computers hand that aren't Jokers
		// This proves to the player no foul play
		for(int j = 0; j < 11; j++)
		{
			if(computerCards.getCard(j).getCardDisplay() != 'X')
			printCard(computerCards.getCard(j));
		}
	}
	// If player has busted. At this stage computer 'wins'
	else if(calculateHandValue(playerCards) > 21)
		cout << "You've busted!\n";
	else
	{ // If computer busted
		cout << "You win!\n" 
			"Computer had:\n";
		for(int j = 0; j < 11; j++)
		{
			if(computerCards.getCard(j).getCardDisplay() != 'X')
			printCard(computerCards.getCard(j));
		}
		cout << "Computer busted!\n";
	}
}
Esempio n. 5
0
void playerTurn(Hand playerCards, Deck GameDeck, int twistIndex)
{
	int usrOption;
	cin >> usrOption; // Take option from user either 1, 2 or 3. Any other is erroneous
	if(calculateHandValue(playerCards) <=12 && usrOption == 3)
	{
		// burn - redeal
		cout << "Burning\n";
		do{
			playerCards.addToHand(generateRandom(4), generateRandom(13), GameDeck, 0);
		}while(playerCards.getCard(0).getCardDisplay() == 'X'); // Joker check
		// Ensures that the card generated is not joker i.e. has not been used

		do{
			playerCards.addToHand(generateRandom(4), generateRandom(13), GameDeck, 1);
		}while(playerCards.getCard(1).getCardDisplay() == 'X'); // Joker check
		// Ensures that the card generated is not joker i.e. has not been used
		
		// Display cards
		cout << "Your hand is:\n";
		printCard(playerCards.getCard(0));
		printCard(playerCards.getCard(1));

		// passes hand value, player hand, deck and false (not stuck) and index
		// to print options. Using Index Ensures card is drawn the card does not replace
		// an existing card
		printOptions(calculateHandValue(playerCards), playerCards, GameDeck, false, twistIndex);
	}
	else if(usrOption == 2 && calculateHandValue(playerCards) < 21)
	{
		// twist
		cout << "Twisting\n";
		if(playerCards.getCard(twistIndex).getCardDisplay() == 'X')
		{
			//stuff
			do{
				playerCards.addToHand(generateRandom(4), generateRandom(13), GameDeck, twistIndex);
			}while(playerCards.getCard(twistIndex).getCardDisplay() == 'X'); // Joker check
			// Ensures that the card generated is not joker i.e. has not been used
			twistIndex++;

			cout << "Your hand is:\n";
			for(int j = 0; j < 11; j++)
			{
				if(playerCards.getCard(j).getCardDisplay() != 'X')
					printCard(playerCards.getCard(j));
			}
		}
		//end if
		printOptions(calculateHandValue(playerCards), playerCards, GameDeck, false, twistIndex);
	}
	else if(usrOption == 1)
	{
		// stick - begin comp turn
		cout << "Stuck\n";
		// Causes loop to exit - Computer turn now begins
	}
	else
	{
		cout << "Invalid option, please retry\n";
		printOptions(calculateHandValue(playerCards), playerCards, GameDeck, false, twistIndex);
	}
}