gtheler 5 лет назад
Родитель
Сommit
9a26126c13
9 измененных файлов: 43 добавлений и 17 удалений
  1. +3
    -2
      blackjack.conf
  2. +2
    -3
      src/base.h
  3. +9
    -4
      src/blackjack.cpp
  4. +4
    -1
      src/blackjack.h
  5. +5
    -0
      src/conf.cpp
  6. +6
    -1
      src/conf.h
  7. +4
    -4
      src/main.cpp
  8. +9
    -1
      src/tty.cpp
  9. +1
    -1
      src/tty.h

+ 3
- 2
blackjack.conf Просмотреть файл

hola = pianola
pistola
hands = 1
flat_bet = 0


+ 2
- 3
src/base.h Просмотреть файл

PlayerActionRequired actionRequired = PlayerActionRequired::None; PlayerActionRequired actionRequired = PlayerActionRequired::None;
PlayerActionTaken actionTaken = PlayerActionTaken::None; PlayerActionTaken actionTaken = PlayerActionTaken::None;
// bool hasDoubled = false;
bool bustedAllHands = false; bool bustedAllHands = false;


unsigned int currentSplits = 0; unsigned int currentSplits = 0;
unsigned int flatBet = 1;
unsigned int currentBet = 0; unsigned int currentBet = 0;
unsigned int n_hands = 0; // this is different from the dealer's due to splitting unsigned int n_hands = 0; // this is different from the dealer's due to splitting
unsigned int handsInsured = 0; unsigned int handsInsured = 0;
unsigned int handsDoubled = 0; unsigned int handsDoubled = 0;
unsigned int blackjacksPlayer = 0; unsigned int blackjacksPlayer = 0;
unsigned int losses = 0; unsigned int losses = 0;
// TODO: blackjack_pushes? // TODO: blackjack_pushes?
unsigned int flat_bet = 1;
bool no_insurance = false; bool no_insurance = false;
bool always_insure = false; bool always_insure = false;

+ 9
- 4
src/blackjack.cpp Просмотреть файл



#include "blackjack.h" #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 // TODO: seed instead of dev_random
std::random_device random_device; std::random_device random_device;
lastPass = false; lastPass = false;
} }
if (player->flatBet) {
player->currentHand->bet = player->flatBet;
if (player->flat_bet) {
player->currentHand->bet = player->flat_bet;
nextAction = DealerAction::DealPlayerFirstCard; nextAction = DealerAction::DealPlayerFirstCard;
} else { } else {
nextAction = DealerAction::AskForBets; nextAction = DealerAction::AskForBets;

+ 4
- 1
src/blackjack.h Просмотреть файл



#ifndef BLACKJACK_H #ifndef BLACKJACK_H
#define BLACKJACK_H #define BLACKJACK_H

#include "base.h" #include "base.h"
#include "conf.h"

class Blackjack : public Dealer { class Blackjack : public Dealer {
public: public:
Blackjack();
Blackjack(Configuration &);
~Blackjack(); ~Blackjack();
void shuffle() override; void shuffle() override;

+ 5
- 0
src/conf.cpp Просмотреть файл

name = line.substr(0, delimiterPos); name = line.substr(0, delimiterPos);
value = line.substr(delimiterPos + 1); value = line.substr(delimiterPos + 1);
data[name] = value; data[name] = value;
// TODO: add another map of string to bools to mark wheter the option was used or not
} }
} }
} else { } else {
} }


int Configuration::getInt(std::string key) {
auto it = data.find(key);
return (it != data.end()) ? std::stoi(it->second) : 0;
}


Configuration::~Configuration() { Configuration::~Configuration() {
data.clear(); data.clear();

+ 6
- 1
src/conf.h Просмотреть файл

public: public:
Configuration(std::string = "", bool = false); Configuration(std::string = "", bool = false);
~Configuration(); ~Configuration();

bool exists(std::string key) { return !(data.find(key) == data.end()); }

void show(void); void show(void);
bool getBool(std::string);
int getInt(std::string);
std::string getString(std::string);
private: private:
std::map<std::string, std::string> data; std::map<std::string, std::string> data;

+ 4
- 4
src/main.cpp Просмотреть файл

Player *player = nullptr; Player *player = nullptr;
Configuration conf; Configuration conf;
conf.show();
// 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(conf);
if (isatty(1)) { if (isatty(1)) {
player = new Tty();
player = new Tty(conf);
} else { } else {
player = new StdInOut(); player = new StdInOut();
} }
// TODO: player strategy from file // TODO: player strategy from file
dealer->nextAction = DealerAction::StartNewHand; dealer->nextAction = DealerAction::StartNewHand;
while (!dealer->finished()) { while (!dealer->finished()) {

+ 9
- 1
src/tty.cpp Просмотреть файл

#include <readline/history.h> #include <readline/history.h>
#endif #endif


#include "conf.h"
#include "blackjack.h" #include "blackjack.h"
#include "tty.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 #ifdef HAVE_LIBREADLINE
prompt = cyan + " > " + reset; prompt = cyan + " > " + reset;
#endif #endif

+ 1
- 1
src/tty.h Просмотреть файл



class Tty : public Player { class Tty : public Player {
public: public:
Tty();
Tty(Configuration &);
~Tty() { ~Tty() {
std::cout << "bye!" << std::endl; std::cout << "bye!" << std::endl;
}; };

Загрузка…
Отмена
Сохранить