| @@ -18,7 +18,6 @@ blackjack_LDADD = $(all_libraries) | |||
| blackjack_SOURCES = \ | |||
| src/main.cpp \ | |||
| src/conf.cpp \ | |||
| src/base.cpp \ | |||
| src/blackjack.cpp \ | |||
| src/cards.cpp \ | |||
| src/stdinout.cpp \ | |||
| @@ -1,90 +0,0 @@ | |||
| /*------------ -------------- -------- --- ----- --- -- - - | |||
| * Libre Blackjack - base classes | |||
| * | |||
| * Copyright (C) 2020 jeremy theler | |||
| * | |||
| * This file is part of Libre Blackjack. | |||
| * | |||
| * Libre Blackjack is free software: you can redistribute it and/or modify | |||
| * it under the terms of the GNU General Public License as published by | |||
| * the Free Software Foundation, either version 3 of the License, or | |||
| * (at your option) any later version. | |||
| * | |||
| * Libre Blackjack is distributed in the hope that it will be useful, | |||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| * GNU General Public License for more details. | |||
| * | |||
| * You should have received a copy of the GNU General Public License | |||
| * along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>. | |||
| *------------------- ------------ ---- -------- -- - - - | |||
| */ | |||
| #include <iostream> | |||
| #include "base.h" | |||
| void Hand::render(bool holeCardShown) { | |||
| for (auto it : cards) { | |||
| std::cout << " _____ "; | |||
| } | |||
| std::cout << std::endl; | |||
| unsigned int i = 0; | |||
| for (auto it : cards) { | |||
| if (holeCardShown || i != 1) { | |||
| std::cout << "|" << card[it].getNumberASCII() << ((card[it].number != 10)?" ":"") << " | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : cards) { | |||
| if (holeCardShown || i != 1) { | |||
| std::cout << "| | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : cards) { | |||
| if (holeCardShown || i != 1) { | |||
| std::cout << "| " << card[it].getSuitUTF8() << " | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : cards) { | |||
| if (holeCardShown || i != 1) { | |||
| std::cout << "| | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : cards) { | |||
| if (holeCardShown || i != 1) { | |||
| std::cout << "|___" << ((card[it].number != 10)?"_":"") << card[it].getNumberASCII() << "| "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| return; | |||
| } | |||
| @@ -137,7 +137,7 @@ extern Card card[52]; | |||
| class Hand { | |||
| public: | |||
| std::list<unsigned int> cards; | |||
| std::list<int> cards; | |||
| // inline on purpose | |||
| int total() { | |||
| @@ -168,8 +168,6 @@ class Hand { | |||
| bool busted() { | |||
| return (abs(total()) > 21); | |||
| } | |||
| void render(bool = true); | |||
| }; | |||
| class PlayerHand : public Hand { | |||
| @@ -283,9 +283,6 @@ void Blackjack::deal(Player *player) { | |||
| player->actionRequired = PlayerActionRequired::Play; | |||
| nextAction = DealerAction::AskForPlay; | |||
| // hand.render(hand.holeCardShown); | |||
| // player->currentHand->render(); | |||
| std::cout << "dealer upcard is " << card[upCard].utf8() << std::endl; | |||
| std::cout << "your total is " << player->currentHand->total() << std::endl; | |||
| std::cout << "play please" << std::endl; | |||
| @@ -301,7 +298,6 @@ void Blackjack::deal(Player *player) { | |||
| } else { | |||
| std::cout << "card_player " << card[playerCard].utf8() << std::endl; | |||
| } | |||
| // player->currentHand->render(); | |||
| if (player->currentHand->total() == 21) { | |||
| player->actionRequired = PlayerActionRequired::None; | |||
| @@ -327,8 +323,6 @@ void Blackjack::deal(Player *player) { | |||
| std::cout << "card_dealer_hole " << card[holeCard].utf8() << std::endl; | |||
| hand.holeCardShown = true; | |||
| std::cout << "dealer_hand" << std::endl; | |||
| // hand.render(hand.holeCardShown); | |||
| // TODO: no tengo que sacarle todo el dinero? | |||
| player->actionRequired = PlayerActionRequired::None; | |||
| @@ -347,8 +341,6 @@ void Blackjack::deal(Player *player) { | |||
| std::cout << "card_dealer_hole" << card[holeCard].utf8() << std::endl; | |||
| hand.holeCardShown = true; | |||
| // hand.render(hand.holeCardShown); | |||
| // TODO: print "soft" | |||
| std::cout << "dealer_count " << hand.total() << std::endl; | |||
| @@ -357,7 +349,6 @@ void Blackjack::deal(Player *player) { | |||
| while (((abs(dealerTotal) < 17 || (hit_soft_17 && dealerTotal == -17))) && hand.busted() == 0) { | |||
| unsigned int dealerCard = drawCard(&hand); | |||
| std::cout << "card_dealer " << card[dealerCard].utf8() << std::endl; | |||
| // hand.render(hand.holeCardShown); | |||
| dealerTotal = abs(hand.total()); | |||
| std::cout << "dealer_count " << dealerTotal << std::endl; | |||
| @@ -482,10 +473,7 @@ int Blackjack::process(Player *player) { | |||
| return 0; | |||
| break; | |||
| case PlayerActionTaken::Table: | |||
| hand.render(hand.holeCardShown); | |||
| for (auto playerHand : player->hands) { | |||
| playerHand.render(); | |||
| } | |||
| std::cout << "TODO" << std::endl; | |||
| return 0; | |||
| break; | |||
| case PlayerActionTaken::None: | |||
| @@ -566,7 +554,6 @@ int Blackjack::process(Player *player) { | |||
| playerCard = drawCard(&(*player->currentHand)); | |||
| unsigned int playerTotal = player->currentHand->total(); | |||
| std::cout << "card_player" << card[playerCard].utf8() << std::endl; | |||
| player->currentHand->render(); | |||
| std::cout << "player_total " << playerTotal << std::endl; | |||
| @@ -630,7 +617,6 @@ int Blackjack::process(Player *player) { | |||
| // deal a card to the first hand | |||
| playerCard = drawCard(&(*player->currentHand)); | |||
| std::cout << "card_player_second " << card[playerCard].utf8() << std::endl; | |||
| player->currentHand->render(); | |||
| // aces get dealt only one card | |||
| // also, if the player gets 21 then we move on to the next hand | |||
| @@ -638,7 +624,6 @@ int Blackjack::process(Player *player) { | |||
| if (++player->currentHand != player->hands.end()) { | |||
| playerCard = drawCard(&(*player->currentHand)); | |||
| std::cout << "card_player_second " << card[playerCard].utf8() << std::endl; | |||
| player->currentHand->render(); | |||
| // if the player got an ace or 21 again, we are done | |||
| if (card[*player->currentHand->cards.begin()].value == 11 || abs(player->currentHand->total()) == 21) { | |||
| @@ -676,7 +661,6 @@ int Blackjack::process(Player *player) { | |||
| ///ip+hit+detail This command can be abbreviated as `h`. | |||
| playerCard = drawCard(&(*player->currentHand)); | |||
| std::cout << "card_player " << card[playerCard].utf8() << std::endl; | |||
| player->currentHand->render(); | |||
| if (player->currentHand->busted()) { | |||
| std::cout << "busted_player " << player->currentHand->total() << std::endl; | |||
| @@ -75,11 +75,12 @@ void Tty::info(Info msg, int intData) { | |||
| case Info::CardDealerHoleDealt: | |||
| // s = "card_dealer_hole"; | |||
| s = "Dealer's hole card is dealt"; | |||
| dealerHand.cards.push_back(-1); | |||
| break; | |||
| case Info::CardDealerHoleRevealed: | |||
| // s = "card_dealer_hole"; | |||
| s = "Dealer's hole card was " + card[intData].utf8(); | |||
| dealerHand.cards.push_back(intData); | |||
| *(++(dealerHand.cards.begin())) = intData; | |||
| break; | |||
| case Info::DealerBlackjack: | |||
| // s = "dealer_blackjack"; | |||
| @@ -135,8 +136,8 @@ void Tty::info(Info msg, int intData) { | |||
| if (msg == Info::CardDealerHoleDealt) { | |||
| dealerHand.render(); | |||
| currentHand->render(); | |||
| render(&dealerHand); | |||
| render(&(*currentHand)); | |||
| } | |||
| return; | |||
| @@ -232,3 +233,71 @@ int Tty::play() { | |||
| return 0; | |||
| } | |||
| void Tty::render(Hand *hand) { | |||
| for (auto it : hand->cards) { | |||
| std::cout << " _____ "; | |||
| } | |||
| std::cout << std::endl; | |||
| unsigned int i = 0; | |||
| for (auto it : hand->cards) { | |||
| if (it > 0) { | |||
| std::cout << "|" << card[it].getNumberASCII() << ((card[it].number != 10)?" ":"") << " | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : hand->cards) { | |||
| if (it > 0) { | |||
| std::cout << "| | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : hand->cards) { | |||
| if (it > 0) { | |||
| std::cout << "| " << card[it].getSuitUTF8() << " | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : hand->cards) { | |||
| if (it > 0) { | |||
| std::cout << "| | "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| i = 0; | |||
| for (auto it : hand->cards) { | |||
| if (it > 0) { | |||
| std::cout << "|___" << ((card[it].number != 10)?"_":"") << card[it].getNumberASCII() << "| "; | |||
| } else { | |||
| std::cout << "|#####| "; | |||
| } | |||
| i++; | |||
| } | |||
| std::cout << std::endl; | |||
| return; | |||
| } | |||
| @@ -32,6 +32,8 @@ class Tty : public Player { | |||
| int play() override; | |||
| void info(Info = Info::None, int = 0) override; | |||
| void render(Hand *); | |||
| private: | |||