| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * 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 <iostream> | ||||
| #include "base.h" | #include "base.h" | ||||
| /*------------ -------------- -------- --- ----- --- -- - - | /*------------ -------------- -------- --- ----- --- -- - - | ||||
| * Libre Blackjack - standard blackjack dealer | |||||
| * Libre Blackjack - base classes | |||||
| * | * | ||||
| * Copyright (C) 2020 jeremy theler | * Copyright (C) 2020 jeremy theler | ||||
| * | * | ||||
| Player(Player &&) = delete; | Player(Player &&) = delete; | ||||
| Player(const Player &&) = delete; | Player(const Player &&) = delete; | ||||
| // TODO: public or getter/setter? | |||||
| /* | |||||
| PlayerAction getNextAction() { | |||||
| return nextAction; | |||||
| } | |||||
| void setNextAction(PlayerAction a) { | |||||
| nextAction = a; | |||||
| } | |||||
| */ | |||||
| virtual int play() = 0; | virtual int play() = 0; | ||||
| virtual void info(Info = Info::None, int = 0) = 0; | virtual void info(Info = Info::None, int = 0) = 0; | ||||
| std::list<PlayerHand> hands; | std::list<PlayerHand> hands; | ||||
| std::list<PlayerHand>::iterator currentHand; | std::list<PlayerHand>::iterator currentHand; | ||||
| DealerHand dealerHand; | |||||
| }; | }; | ||||
| class Dealer { | class Dealer { |
| player->actionRequired = PlayerActionRequired::Play; | player->actionRequired = PlayerActionRequired::Play; | ||||
| nextAction = DealerAction::AskForPlay; | nextAction = DealerAction::AskForPlay; | ||||
| hand.render(hand.holeCardShown); | |||||
| player->currentHand->render(); | |||||
| // hand.render(hand.holeCardShown); | |||||
| // player->currentHand->render(); | |||||
| std::cout << "dealer upcard is " << card[upCard].utf8() << std::endl; | std::cout << "dealer upcard is " << card[upCard].utf8() << std::endl; | ||||
| std::cout << "your total is " << player->currentHand->total() << std::endl; | std::cout << "your total is " << player->currentHand->total() << std::endl; | ||||
| } else { | } else { | ||||
| std::cout << "card_player " << card[playerCard].utf8() << std::endl; | std::cout << "card_player " << card[playerCard].utf8() << std::endl; | ||||
| } | } | ||||
| player->currentHand->render(); | |||||
| // player->currentHand->render(); | |||||
| if (player->currentHand->total() == 21) { | if (player->currentHand->total() == 21) { | ||||
| player->actionRequired = PlayerActionRequired::None; | player->actionRequired = PlayerActionRequired::None; | ||||
| std::cout << "card_dealer_hole " << card[holeCard].utf8() << std::endl; | std::cout << "card_dealer_hole " << card[holeCard].utf8() << std::endl; | ||||
| hand.holeCardShown = true; | hand.holeCardShown = true; | ||||
| std::cout << "dealer_hand" << std::endl; | std::cout << "dealer_hand" << std::endl; | ||||
| hand.render(hand.holeCardShown); | |||||
| // hand.render(hand.holeCardShown); | |||||
| // TODO: no tengo que sacarle todo el dinero? | // TODO: no tengo que sacarle todo el dinero? | ||||
| std::cout << "card_dealer_hole" << card[holeCard].utf8() << std::endl; | std::cout << "card_dealer_hole" << card[holeCard].utf8() << std::endl; | ||||
| hand.holeCardShown = true; | hand.holeCardShown = true; | ||||
| hand.render(hand.holeCardShown); | |||||
| // hand.render(hand.holeCardShown); | |||||
| // TODO: print "soft" | // TODO: print "soft" | ||||
| std::cout << "dealer_count " << hand.total() << std::endl; | std::cout << "dealer_count " << hand.total() << std::endl; | ||||
| while (((abs(dealerTotal) < 17 || (hit_soft_17 && dealerTotal == -17))) && hand.busted() == 0) { | while (((abs(dealerTotal) < 17 || (hit_soft_17 && dealerTotal == -17))) && hand.busted() == 0) { | ||||
| unsigned int dealerCard = drawCard(&hand); | unsigned int dealerCard = drawCard(&hand); | ||||
| std::cout << "card_dealer " << card[dealerCard].utf8() << std::endl; | std::cout << "card_dealer " << card[dealerCard].utf8() << std::endl; | ||||
| hand.render(hand.holeCardShown); | |||||
| // hand.render(hand.holeCardShown); | |||||
| dealerTotal = abs(hand.total()); | dealerTotal = abs(hand.total()); | ||||
| std::cout << "dealer_count " << dealerTotal << std::endl; | std::cout << "dealer_count " << dealerTotal << std::endl; |
| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * Libre Blackjack - fifty-two-deck cards | |||||
| * | |||||
| * 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 "base.h" | #include "base.h" | ||||
| static std::string TJQK[4] = {"T", "J", "Q", "K"}; | static std::string TJQK[4] = {"T", "J", "Q", "K"}; |
| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * Libre Blackjack - configuration handling | |||||
| * | |||||
| * 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 "conf.h" | #include "conf.h" | ||||
| #include <iostream> | #include <iostream> |
| /*------------ -------------- -------- --- ----- --- -- - - | /*------------ -------------- -------- --- ----- --- -- - - | ||||
| * Libre Blackjack - standard blackjack dealer | |||||
| * Libre Blackjack - configuration handling | |||||
| * | * | ||||
| * Copyright (C) 2020 jeremy theler | * Copyright (C) 2020 jeremy theler | ||||
| * | * |
| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * Libre Blackjack - stdio player | |||||
| * | |||||
| * 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 <iostream> | ||||
| #ifdef HAVE_LIBREADLINE | #ifdef HAVE_LIBREADLINE |
| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * Libre Blackjack - stdio player | |||||
| * | |||||
| * 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/>. | |||||
| *------------------- ------------ ---- -------- -- - - - | |||||
| */ | |||||
| #ifndef STDINOUT_H | #ifndef STDINOUT_H | ||||
| #define STDINOUT_H | #define STDINOUT_H | ||||
| #include "blackjack.h" | #include "blackjack.h" |
| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * Libre Blackjack - tty interactive player | |||||
| * | |||||
| * 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 <iostream> | ||||
| #include <cstring> | #include <cstring> | ||||
| #include <thread> | #include <thread> | ||||
| conf.set(&flat_bet, {"flat_bet", "flatbet"}); | conf.set(&flat_bet, {"flat_bet", "flatbet"}); | ||||
| conf.set(&no_insurance, {"no_insurance", "dont_insure"}); | conf.set(&no_insurance, {"no_insurance", "dont_insure"}); | ||||
| #ifdef HAVE_LIBREADLINE | |||||
| // TODO: check conf for colors | |||||
| prompt = cyan + " > " + reset; | prompt = cyan + " > " + reset; | ||||
| #endif | |||||
| } | } | ||||
| void Tty::info(Info msg, int intData) { | void Tty::info(Info msg, int intData) { | ||||
| std::string s; | std::string s; | ||||
| // TODO: choose utf8 or other representation | |||||
| switch (msg) { | switch (msg) { | ||||
| case Info::NewHand: | case Info::NewHand: | ||||
| // s = "new_hand"; | // s = "new_hand"; | ||||
| s = "Starting new hand #" + std::to_string(intData); | s = "Starting new hand #" + std::to_string(intData); | ||||
| dealerHand.cards.clear(); | |||||
| break; | break; | ||||
| case Info::Shuffle: | case Info::Shuffle: | ||||
| // s = "shuffle"; | // s = "shuffle"; | ||||
| case Info::CardDealerUp: | case Info::CardDealerUp: | ||||
| // s = "card_dealer_up"; | // s = "card_dealer_up"; | ||||
| s = "Dealer's up card " + card[intData].utf8(); | s = "Dealer's up card " + card[intData].utf8(); | ||||
| dealerHand.cards.push_back(intData); | |||||
| break; | break; | ||||
| case Info::CardPlayerSecond: | case Info::CardPlayerSecond: | ||||
| // s = "card_player_second"; | // s = "card_player_second"; | ||||
| case Info::CardDealerHoleRevealed: | case Info::CardDealerHoleRevealed: | ||||
| // s = "card_dealer_hole"; | // s = "card_dealer_hole"; | ||||
| s = "Dealer's hole card was " + card[intData].utf8(); | s = "Dealer's hole card was " + card[intData].utf8(); | ||||
| dealerHand.cards.push_back(intData); | |||||
| break; | break; | ||||
| case Info::DealerBlackjack: | case Info::DealerBlackjack: | ||||
| // s = "dealer_blackjack"; | // s = "dealer_blackjack"; | ||||
| if (msg == Info::CardDealerHoleDealt) { | if (msg == Info::CardDealerHoleDealt) { | ||||
| // hand.render(hand.holeCardShown); | |||||
| dealerHand.render(); | |||||
| currentHand->render(); | currentHand->render(); | ||||
| } | } | ||||
| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * Libre Blackjack - tty interactive player | |||||
| * | |||||
| * 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/>. | |||||
| *------------------- ------------ ---- -------- -- - - - | |||||
| */ | |||||
| #ifndef TTY_H | #ifndef TTY_H | ||||
| #define TTY_H | #define TTY_H | ||||
| #include "blackjack.h" | #include "blackjack.h" |