当前位置: 首页>>代码示例>>C++>>正文


C++ Hand::hand_value方法代码示例

本文整理汇总了C++中Hand::hand_value方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::hand_value方法的具体用法?C++ Hand::hand_value怎么用?C++ Hand::hand_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hand的用法示例。


在下文中一共展示了Hand::hand_value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

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();

//.........这里部分代码省略.........
开发者ID:brendanahart,项目名称:Mini-Projects,代码行数:101,代码来源:blackjack.cpp

示例2: main

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()) {
//.........这里部分代码省略.........
开发者ID:amalstrom,项目名称:blackjack,代码行数:101,代码来源:blackjack.cpp


注:本文中的Hand::hand_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。