| @@ -1,3 +1,4 @@ | |||
| hands = 1 | |||
| flat_bet = 0 | |||
| flat_bet = 1 | |||
| max_bet = 2 | |||
| seed=1 | |||
| @@ -28,19 +28,31 @@ | |||
| #include "blackjack.h" | |||
| Blackjack::Blackjack(Configuration &conf) : mt19937(dev_random()), fiftyTwoCards(0, 51) { | |||
| Blackjack::Blackjack(Configuration &conf) : rng(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"); | |||
| } | |||
| conf.set(&n_hands, {"n_hands", "hands"}); | |||
| conf.set(&n_decks, {"decks", "n_decks"}); | |||
| conf.set(&max_bet, {"max_bet", "maxbet"}); | |||
| conf.set(&hit_soft_17, {"h17", "hit_soft_17"}); | |||
| conf.set(&blackjack_pays, {"blackjack_pays"}); | |||
| conf.set(&number_of_burnt_cards, {"number_of_burnt_cards", "n_burnt_cards", "burnt_cards"}); | |||
| // TODO: what's this? | |||
| conf.set(&infinite_decks_card_number_for_arranged_ones, {"infinite_decks_card_number_for_arranged_ones"}); | |||
| bool explicit_seed = conf.set(&rng_seed, {"rng_seed", "seed"}); | |||
| // TODO: seed instead of dev_random | |||
| if (explicit_seed) { | |||
| rng = std::mt19937(rng_seed); | |||
| } | |||
| /* | |||
| std::random_device random_device; | |||
| std::mt19937 random_engine(random_device()); | |||
| std::uniform_int_distribution<int> distribution_1_100(1, 100); | |||
| */ | |||
| } | |||
| Blackjack::~Blackjack() { | |||
| @@ -729,7 +741,7 @@ unsigned int Blackjack::drawCard(Hand *hand) { | |||
| if (n_decks == -1) { | |||
| // TODO: arranged cards | |||
| tag = fiftyTwoCards(mt19937); | |||
| tag = fiftyTwoCards(rng); | |||
| } else { | |||
| // TODO: shoes | |||
| @@ -38,9 +38,10 @@ class Blackjack : public Dealer { | |||
| private: | |||
| unsigned int rng_seed; | |||
| std::random_device dev_random; | |||
| std::mt19937 mt19937; | |||
| std::uniform_int_distribution<int> fiftyTwoCards; | |||
| std::mt19937 rng; | |||
| std::uniform_int_distribution<unsigned int> fiftyTwoCards; | |||
| bool lastPass = false; | |||
| @@ -141,6 +141,62 @@ int Configuration::readConfigFile(std::string filePath, bool mandatory) { | |||
| } | |||
| bool Configuration::set(bool *value, std::list<std::string> key) { | |||
| for (auto it : key) { | |||
| if (exists(*(&it))) { | |||
| if (data[*(&it)] == "true") { | |||
| *value = true; | |||
| } else if (data[*(&it)] == "false") { | |||
| *value = false; | |||
| } else { | |||
| *value = std::stoi(data[*(&it)]); | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| bool Configuration::set(int *value, std::list<std::string> key) { | |||
| for (auto it : key) { | |||
| if (exists(*(&it))) { | |||
| *value = std::stoi(data[*(&it)]); | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| bool Configuration::set(unsigned int *value, std::list<std::string> key) { | |||
| for (auto it : key) { | |||
| if (exists(*(&it))) { | |||
| *value = std::stoi(data[*(&it)]); | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| bool Configuration::set(unsigned long int *value, std::list<std::string> key) { | |||
| for (auto it : key) { | |||
| if (exists(*(&it))) { | |||
| *value = std::stoi(data[*(&it)]); | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| bool Configuration::set(double *value, std::list<std::string> key) { | |||
| for (auto it : key) { | |||
| if (exists(*(&it))) { | |||
| *value = std::stof(data[*(&it)]); | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| void Configuration::show(void) { | |||
| for (auto &it : data) { | |||
| @@ -23,6 +23,8 @@ | |||
| #ifndef CONF_H | |||
| #define CONF_H | |||
| #include <string> | |||
| #include <list> | |||
| #include <map> | |||
| class Configuration { | |||
| @@ -32,8 +34,13 @@ class Configuration { | |||
| int readConfigFile(std::string, bool = false); | |||
| // bool exists(std::string key) { return !(data.find(key) == data.end()); } | |||
| bool exists(std::string key) { return (data.count(key) != 0); } | |||
| bool set(bool *, std::list<std::string>); | |||
| bool set(int *, std::list<std::string>); | |||
| bool set(unsigned int *, std::list<std::string>); | |||
| bool set(long unsigned int *, std::list<std::string>); | |||
| bool set(double *, std::list<std::string>); | |||
| void show(void); | |||