| @@ -17,6 +17,7 @@ blackjack_LDADD = $(all_libraries) | |||
| blackjack_SOURCES = \ | |||
| src/main.cpp \ | |||
| src/conf.cpp \ | |||
| src/base.cpp \ | |||
| src/blackjack.cpp \ | |||
| src/cards.cpp \ | |||
| @@ -1,7 +1,9 @@ | |||
| * version and copyright | |||
| * messages implemented on the player's side | |||
| * configuration files as map of strings to strings https://www.walletfox.com/course/parseconfigfile.php | |||
| * arranged shoes | |||
| * multithreading | |||
| * deterministic seeds | |||
| * better RNGs | |||
| * ENHC | |||
| * blackjack switch | |||
| * siete y medio | |||
| @@ -0,0 +1,2 @@ | |||
| hola = pianola | |||
| pistola | |||
| @@ -0,0 +1,50 @@ | |||
| #include "conf.h" | |||
| #include <iostream> | |||
| #include <fstream> | |||
| #include <algorithm> | |||
| #include <map> | |||
| // source https://www.walletfox.com/course/parseconfigfile.php | |||
| Configuration::Configuration(std::string filePath, bool mandatory) { | |||
| // std::ifstream is RAII, i.e. no need to call close | |||
| std::ifstream fileStream((filePath != "") ? filePath : "./blackjack.conf"); | |||
| std::size_t delimiterPos; | |||
| std::string name; | |||
| std::string value; | |||
| if (fileStream.is_open()) { | |||
| std::string line; | |||
| while(getline(fileStream, line)) { | |||
| line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end()); | |||
| if (line[0] == '#' || line[0] == ';' || line.empty()) { | |||
| continue; | |||
| } | |||
| delimiterPos = line.find("="); | |||
| if (delimiterPos != std::string::npos) { | |||
| name = line.substr(0, delimiterPos); | |||
| value = line.substr(delimiterPos + 1); | |||
| data[name] = value; | |||
| } | |||
| } | |||
| } else { | |||
| std::cerr << "Couldn't open config file for reading.\n"; | |||
| } | |||
| } | |||
| void Configuration::show(void) { | |||
| for (auto &it : data) { | |||
| std::cout << it.first << " = " << it.second << std::endl; | |||
| } | |||
| } | |||
| Configuration::~Configuration() { | |||
| data.clear(); | |||
| } | |||
| @@ -0,0 +1,38 @@ | |||
| /*------------ -------------- -------- --- ----- --- -- - - | |||
| * Libre Blackjack - standard blackjack dealer | |||
| * | |||
| * 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 CONF_H | |||
| #define CONF_H | |||
| #include <map> | |||
| class Configuration { | |||
| public: | |||
| Configuration(std::string = "", bool = false); | |||
| ~Configuration(); | |||
| void show(void); | |||
| private: | |||
| std::map<std::string, std::string> data; | |||
| }; | |||
| #endif | |||
| @@ -24,6 +24,7 @@ | |||
| #include <unistd.h> | |||
| #include "base.h" | |||
| #include "conf.h" | |||
| #include "blackjack.h" | |||
| #include "tty.h" | |||
| #include "stdinout.h" | |||
| @@ -33,6 +34,9 @@ int main(int argc, char **argv) { | |||
| Dealer *dealer = nullptr; | |||
| Player *player = nullptr; | |||
| Configuration conf; | |||
| 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(); | |||
| @@ -52,7 +52,7 @@ int Tty::play() { | |||
| switch (actionRequired) { | |||
| case PlayerActionRequired::Bet: | |||
| currentBet = atoi(input_buffer); | |||
| currentBet = std::stoi(input_buffer); | |||
| actionTaken = PlayerActionTaken::Bet; | |||
| break; | |||