| ; flat_bet = 1 | ; flat_bet = 1 | ||||
| ; arranged_cards = 3,8,3,13,4,13,11,7 | |||||
| arranged_cards = 3,8,16 | |||||
| rng_seed = 5 | |||||
| ; delay = 0 | ; delay = 0 | ||||
| PlayerActionRequired actionRequired = PlayerActionRequired::None; | PlayerActionRequired actionRequired = PlayerActionRequired::None; | ||||
| PlayerActionTaken actionTaken = PlayerActionTaken::None; | PlayerActionTaken actionTaken = PlayerActionTaken::None; | ||||
| // TODO: one for the dealer and one for the player | |||||
| unsigned int currentSplits = 0; | unsigned int currentSplits = 0; | ||||
| unsigned int currentBet = 0; | unsigned int currentBet = 0; | ||||
| std::list<PlayerHand> hands; | std::list<PlayerHand> hands; | ||||
| std::list<PlayerHand>::iterator currentHand; | std::list<PlayerHand>::iterator currentHand; | ||||
| std::size_t currentHandId = 0; | |||||
| Hand dealerHand; | Hand dealerHand; | ||||
| // see if we finished all the player's hands | // see if we finished all the player's hands | ||||
| if (++player->currentHand != player->hands.end()) { | if (++player->currentHand != player->hands.end()) { | ||||
| unsigned int playerCard = drawCard(&(*player->currentHand)); | unsigned int playerCard = drawCard(&(*player->currentHand)); | ||||
| info(player, Info::CardPlayer, playerCard); | |||||
| info(player, Info::CardPlayer, playerCard, player->currentHand->id); | |||||
| if (std::abs(player->currentHand->total()) == 21) { | if (std::abs(player->currentHand->total()) == 21) { | ||||
| player->actionRequired = PlayerActionRequired::None; | player->actionRequired = PlayerActionRequired::None; | ||||
| playerCard = drawCard(&(*player->currentHand)); | playerCard = drawCard(&(*player->currentHand)); | ||||
| unsigned int playerTotal = player->currentHand->total(); | unsigned int playerTotal = player->currentHand->total(); | ||||
| info(player, Info::CardPlayer, playerCard); | |||||
| info(player, Info::CardPlayer, playerCard, player->currentHand->id); | |||||
| if (player->currentHand->busted()) { | if (player->currentHand->busted()) { | ||||
| info(player, Info::PlayerLosses, 1e3*player->currentHand->bet, playerTotal); | info(player, Info::PlayerLosses, 1e3*player->currentHand->bet, playerTotal); | ||||
| // deal a card to the first hand | // deal a card to the first hand | ||||
| playerCard = drawCard(&(*player->currentHand)); | playerCard = drawCard(&(*player->currentHand)); | ||||
| info(player, Info::CardPlayer, playerCard); | |||||
| info(player, Info::CardPlayer, playerCard, player->currentHand->id); | |||||
| // aces get dealt only one card | // aces get dealt only one card | ||||
| // also, if the player gets 21 then we move on to the next hand | // also, if the player gets 21 then we move on to the next hand | ||||
| if (++player->currentHand != player->hands.end()) { | if (++player->currentHand != player->hands.end()) { | ||||
| info(player, Info::PlayerNextHand, (*player->currentHand).id); | info(player, Info::PlayerNextHand, (*player->currentHand).id); | ||||
| playerCard = drawCard(&(*player->currentHand)); | playerCard = drawCard(&(*player->currentHand)); | ||||
| info(player, Info::CardPlayer, playerCard); | |||||
| info(player, Info::CardPlayer, playerCard, player->currentHand->id); | |||||
| // if the player got an ace or 21 again, we are done | // if the player got an ace or 21 again, we are done | ||||
| if (card[*player->currentHand->cards.begin()].value == 11 || std::abs(player->currentHand->total()) == 21) { | if (card[*player->currentHand->cards.begin()].value == 11 || std::abs(player->currentHand->total()) == 21) { | ||||
| ///ip+hit+detail | ///ip+hit+detail | ||||
| ///ip+hit+detail This command can be abbreviated as `h`. | ///ip+hit+detail This command can be abbreviated as `h`. | ||||
| playerCard = drawCard(&(*player->currentHand)); | playerCard = drawCard(&(*player->currentHand)); | ||||
| info(player, Info::CardPlayer, playerCard); | |||||
| info(player, Info::CardPlayer, playerCard, player->currentHand->id); | |||||
| if (player->currentHand->busted()) { | if (player->currentHand->busted()) { | ||||
| info(player, Info::PlayerLosses, 1e3*player->currentHand->bet); | info(player, Info::PlayerLosses, 1e3*player->currentHand->bet); |
| break; | break; | ||||
| case Info::CardPlayer: | case Info::CardPlayer: | ||||
| switch (currentHand->cards.size()) { | |||||
| case 1: | |||||
| // s = "card_player_first"; | |||||
| s = "Player's first card is " + card[p1].utf8(); | |||||
| break; | |||||
| case 2: | |||||
| // s = "card_player_second"; | |||||
| s = "Player's second card is " + card[p1].utf8(); | |||||
| break; | |||||
| default: | |||||
| // s = "card_player"; | |||||
| s = "Player's card is " + card[p1].utf8(); | |||||
| break; | |||||
| } | |||||
| // s = "card_player"; | |||||
| currentHandId = p2; | |||||
| s = "Player's card" + ((p2 != 0)?(" in hand #"+std::to_string(p2)):"") + " is " + card[p1].utf8(); | |||||
| break; | |||||
| break; | break; | ||||
| case Info::CardDealer: | case Info::CardDealer: | ||||
| s = "No blackjacks"; | s = "No blackjacks"; | ||||
| break; | break; | ||||
| /* | |||||
| case Info::PlayerBustsAllHands: | |||||
| // s = "player_busted_all_hands"; | |||||
| if (hands.size() == 1) { | |||||
| s = "Player busted"; | |||||
| } else { | |||||
| s = "Player busted all hands"; | |||||
| } | |||||
| renderTable(); | |||||
| break; | |||||
| */ | |||||
| case Info::DealerBusts: | case Info::DealerBusts: | ||||
| // s = "no_blackjacks"; | // s = "no_blackjacks"; | ||||
| s = "Dealer busts with " + std::to_string(p1); | s = "Dealer busts with " + std::to_string(p1); | ||||
| } else if (command == "s" || command == "stand") { | } else if (command == "s" || command == "stand") { | ||||
| actionTaken = PlayerActionTaken::Stand; | actionTaken = PlayerActionTaken::Stand; | ||||
| } else if (command == "d" || command == "double") { | } else if (command == "d" || command == "double") { | ||||
| actionTaken = PlayerActionTaken::Stand; | |||||
| actionTaken = PlayerActionTaken::Double; | |||||
| } else if (command == "p" || command == "split" || command == "pair") { | } else if (command == "p" || command == "split" || command == "pair") { | ||||
| actionTaken = PlayerActionTaken::Split; | actionTaken = PlayerActionTaken::Split; | ||||
| } else { | } else { | ||||
| std::cout << " -- Player's hand --------" << std::endl; | std::cout << " -- Player's hand --------" << std::endl; | ||||
| for (auto hand : hands) { | for (auto hand : hands) { | ||||
| renderHand(&hand); | |||||
| renderHand(&hand, (hand.id != 0) && (hand.id == currentHandId)); | |||||
| std::cout << " Total: " << ((hand.total() < 0)?"soft ":"") << std::abs(hand.total()) << std::endl; | std::cout << " Total: " << ((hand.total() < 0)?"soft ":"") << std::abs(hand.total()) << std::endl; | ||||
| } | } | ||||
| return; | return; | ||||
| } | } | ||||
| void Tty::renderHand(Hand *hand) { | |||||
| void Tty::renderHand(Hand *hand, bool current) { | |||||
| std::string ansiColor; | std::string ansiColor; | ||||
| std::string ansiReset; | std::string ansiReset; | ||||
| } | } | ||||
| std::cout << std::endl; | std::cout << std::endl; | ||||
| std::cout << "hand id = " << hand->id << std::endl; | |||||
| for (auto c : hand->cards) { | for (auto c : hand->cards) { | ||||
| if (color && (card[c].suit == Suit::Diamonds || card[c].suit == Suit::Hearts)) { | if (color && (card[c].suit == Suit::Diamonds || card[c].suit == Suit::Hearts)) { | ||||
| ansiColor = red; | ansiColor = red; | ||||
| std::cout << "|#####| "; | std::cout << "|#####| "; | ||||
| } | } | ||||
| } | } | ||||
| if (current) { | |||||
| std::cout << cyan << "<-- current hand" << reset; | |||||
| } | |||||
| std::cout << std::endl; | std::cout << std::endl; | ||||
| for (auto c : hand->cards) { | for (auto c : hand->cards) { |
| private: | private: | ||||
| void renderHand(Hand *); | |||||
| void renderHand(Hand *, bool = false); | |||||
| void renderTable(void); | void renderTable(void); | ||||
| #ifdef HAVE_LIBREADLINE | #ifdef HAVE_LIBREADLINE |