| @@ -1,2 +1,3 @@ | |||
| hola = pianola | |||
| pistola | |||
| hands = 1 | |||
| flat_bet = 0 | |||
| @@ -193,15 +193,13 @@ class Player { | |||
| PlayerActionRequired actionRequired = PlayerActionRequired::None; | |||
| PlayerActionTaken actionTaken = PlayerActionTaken::None; | |||
| // bool hasDoubled = false; | |||
| bool bustedAllHands = false; | |||
| unsigned int currentSplits = 0; | |||
| unsigned int flatBet = 1; | |||
| unsigned int currentBet = 0; | |||
| unsigned int n_hands = 0; // this is different from the dealer's due to splitting | |||
| unsigned int handsInsured = 0; | |||
| unsigned int handsDoubled = 0; | |||
| unsigned int blackjacksPlayer = 0; | |||
| @@ -219,6 +217,7 @@ class Player { | |||
| unsigned int losses = 0; | |||
| // TODO: blackjack_pushes? | |||
| unsigned int flat_bet = 1; | |||
| bool no_insurance = false; | |||
| bool always_insure = false; | |||
| @@ -28,8 +28,13 @@ | |||
| #include "blackjack.h" | |||
| Blackjack::Blackjack() : mt19937(dev_random()), fiftyTwoCards(0, 51) { | |||
| std::cout << "I'm your Blackjack dealer!" << std::endl; | |||
| Blackjack::Blackjack(Configuration &conf) : mt19937(dev_random()), fiftyTwoCards(0, 51) { | |||
| if (conf.exists("n_hands")) { | |||
| n_hands = conf.getInt("n_hands"); | |||
| } else if (conf.exists("hands")) { | |||
| n_hands = conf.getInt("hands"); | |||
| } | |||
| // TODO: seed instead of dev_random | |||
| std::random_device random_device; | |||
| @@ -111,8 +116,8 @@ void Blackjack::deal(Player *player) { | |||
| lastPass = false; | |||
| } | |||
| if (player->flatBet) { | |||
| player->currentHand->bet = player->flatBet; | |||
| if (player->flat_bet) { | |||
| player->currentHand->bet = player->flat_bet; | |||
| nextAction = DealerAction::DealPlayerFirstCard; | |||
| } else { | |||
| nextAction = DealerAction::AskForBets; | |||
| @@ -22,10 +22,13 @@ | |||
| #ifndef BLACKJACK_H | |||
| #define BLACKJACK_H | |||
| #include "base.h" | |||
| #include "conf.h" | |||
| class Blackjack : public Dealer { | |||
| public: | |||
| Blackjack(); | |||
| Blackjack(Configuration &); | |||
| ~Blackjack(); | |||
| void shuffle() override; | |||
| @@ -29,6 +29,7 @@ Configuration::Configuration(std::string filePath, bool mandatory) { | |||
| name = line.substr(0, delimiterPos); | |||
| value = line.substr(delimiterPos + 1); | |||
| data[name] = value; | |||
| // TODO: add another map of string to bools to mark wheter the option was used or not | |||
| } | |||
| } | |||
| } else { | |||
| @@ -44,6 +45,10 @@ void Configuration::show(void) { | |||
| } | |||
| int Configuration::getInt(std::string key) { | |||
| auto it = data.find(key); | |||
| return (it != data.end()) ? std::stoi(it->second) : 0; | |||
| } | |||
| Configuration::~Configuration() { | |||
| data.clear(); | |||
| @@ -29,8 +29,13 @@ class Configuration { | |||
| public: | |||
| Configuration(std::string = "", bool = false); | |||
| ~Configuration(); | |||
| bool exists(std::string key) { return !(data.find(key) == data.end()); } | |||
| void show(void); | |||
| bool getBool(std::string); | |||
| int getInt(std::string); | |||
| std::string getString(std::string); | |||
| private: | |||
| std::map<std::string, std::string> data; | |||
| @@ -35,18 +35,18 @@ int main(int argc, char **argv) { | |||
| Player *player = nullptr; | |||
| Configuration conf; | |||
| conf.show(); | |||
| // conf.show(); | |||
| // TODO: read the args/conf to know what kind of dealer and player we are having | |||
| // TODO: pass args/conf to the constructor | |||
| dealer = new Blackjack(); | |||
| dealer = new Blackjack(conf); | |||
| if (isatty(1)) { | |||
| player = new Tty(); | |||
| player = new Tty(conf); | |||
| } else { | |||
| player = new StdInOut(); | |||
| } | |||
| // TODO: player strategy from file | |||
| dealer->nextAction = DealerAction::StartNewHand; | |||
| while (!dealer->finished()) { | |||
| @@ -6,10 +6,18 @@ | |||
| #include <readline/history.h> | |||
| #endif | |||
| #include "conf.h" | |||
| #include "blackjack.h" | |||
| #include "tty.h" | |||
| Tty::Tty(void) { | |||
| Tty::Tty(Configuration &conf) { | |||
| if (conf.exists("flat_bet")) { | |||
| flat_bet = conf.getInt("flat_bet"); | |||
| } else if (conf.exists("flat_bet")) { | |||
| flat_bet = conf.getInt("flat_bet"); | |||
| } | |||
| #ifdef HAVE_LIBREADLINE | |||
| prompt = cyan + " > " + reset; | |||
| #endif | |||
| @@ -4,7 +4,7 @@ | |||
| class Tty : public Player { | |||
| public: | |||
| Tty(); | |||
| Tty(Configuration &); | |||
| ~Tty() { | |||
| std::cout << "bye!" << std::endl; | |||
| }; | |||