| blackjack_SOURCES = \ | blackjack_SOURCES = \ | ||||
| src/main.cpp \ | src/main.cpp \ | ||||
| src/conf.cpp \ | |||||
| src/base.cpp \ | src/base.cpp \ | ||||
| src/blackjack.cpp \ | src/blackjack.cpp \ | ||||
| src/cards.cpp \ | src/cards.cpp \ |
| * 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 | * arranged shoes | ||||
| * multithreading | * multithreading | ||||
| * deterministic seeds | * deterministic seeds | ||||
| * better RNGs | |||||
| * ENHC | * ENHC | ||||
| * blackjack switch | * blackjack switch | ||||
| * siete y medio | * siete y medio |
| hola = pianola | |||||
| pistola |
| #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(); | |||||
| } |
| /*------------ -------------- -------- --- ----- --- -- - - | |||||
| * 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 |
| #include <unistd.h> | #include <unistd.h> | ||||
| #include "base.h" | #include "base.h" | ||||
| #include "conf.h" | |||||
| #include "blackjack.h" | #include "blackjack.h" | ||||
| #include "tty.h" | #include "tty.h" | ||||
| #include "stdinout.h" | #include "stdinout.h" | ||||
| Dealer *dealer = nullptr; | Dealer *dealer = nullptr; | ||||
| Player *player = 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: read the args/conf to know what kind of dealer and player we are having | ||||
| // TODO: pass args/conf to the constructor | // TODO: pass args/conf to the constructor | ||||
| dealer = new Blackjack(); | dealer = new Blackjack(); |
| switch (actionRequired) { | switch (actionRequired) { | ||||
| case PlayerActionRequired::Bet: | case PlayerActionRequired::Bet: | ||||
| currentBet = atoi(input_buffer); | |||||
| currentBet = std::stoi(input_buffer); | |||||
| actionTaken = PlayerActionTaken::Bet; | actionTaken = PlayerActionTaken::Bet; | ||||
| break; | break; | ||||