| hands = 1 | |||||
| flat_bet = 0 | |||||
| flat_bet = 1 | |||||
| max_bet = 2 | |||||
| seed=1 | |||||
| #include "blackjack.h" | #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 | // TODO: seed instead of dev_random | ||||
| if (explicit_seed) { | |||||
| rng = std::mt19937(rng_seed); | |||||
| } | |||||
| /* | |||||
| std::random_device random_device; | std::random_device random_device; | ||||
| std::mt19937 random_engine(random_device()); | std::mt19937 random_engine(random_device()); | ||||
| std::uniform_int_distribution<int> distribution_1_100(1, 100); | std::uniform_int_distribution<int> distribution_1_100(1, 100); | ||||
| */ | |||||
| } | } | ||||
| Blackjack::~Blackjack() { | Blackjack::~Blackjack() { | ||||
| if (n_decks == -1) { | if (n_decks == -1) { | ||||
| // TODO: arranged cards | // TODO: arranged cards | ||||
| tag = fiftyTwoCards(mt19937); | |||||
| tag = fiftyTwoCards(rng); | |||||
| } else { | } else { | ||||
| // TODO: shoes | // TODO: shoes |
| private: | private: | ||||
| unsigned int rng_seed; | |||||
| std::random_device dev_random; | 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; | bool lastPass = false; | ||||
| } | } | ||||
| 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) { | void Configuration::show(void) { | ||||
| for (auto &it : data) { | for (auto &it : data) { |
| #ifndef CONF_H | #ifndef CONF_H | ||||
| #define CONF_H | #define CONF_H | ||||
| #include <string> | |||||
| #include <list> | |||||
| #include <map> | #include <map> | ||||
| class Configuration { | class Configuration { | ||||
| int readConfigFile(std::string, bool = false); | 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 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); | void show(void); |