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


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

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


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

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