gtheler 5 anos atrás
pai
commit
9a26126c13
9 arquivos alterados com 43 adições e 17 exclusões
  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 Ver arquivo

@@ -1,2 +1,3 @@
hola = pianola
pistola
hands = 1
flat_bet = 0


+ 2
- 3
src/base.h Ver arquivo

@@ -193,15 +193,13 @@ class Player {
PlayerActionRequired actionRequired = PlayerActionRequired::None;
PlayerActionTaken actionTaken = PlayerActionTaken::None;
// bool hasDoubled = false;
bool bustedAllHands = false;

unsigned int currentSplits = 0;
unsigned int flatBet = 1;
unsigned int currentBet = 0;
unsigned int n_hands = 0; // this is different from the dealer's due to splitting
unsigned int handsInsured = 0;
unsigned int handsDoubled = 0;
unsigned int blackjacksPlayer = 0;
@@ -219,6 +217,7 @@ class Player {
unsigned int losses = 0;
// TODO: blackjack_pushes?
unsigned int flat_bet = 1;
bool no_insurance = false;
bool always_insure = false;

+ 9
- 4
src/blackjack.cpp Ver arquivo

@@ -28,8 +28,13 @@

#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
std::random_device random_device;
@@ -111,8 +116,8 @@ void Blackjack::deal(Player *player) {
lastPass = false;
}
if (player->flatBet) {
player->currentHand->bet = player->flatBet;
if (player->flat_bet) {
player->currentHand->bet = player->flat_bet;
nextAction = DealerAction::DealPlayerFirstCard;
} else {
nextAction = DealerAction::AskForBets;

+ 4
- 1
src/blackjack.h Ver arquivo

@@ -22,10 +22,13 @@

#ifndef BLACKJACK_H
#define BLACKJACK_H

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

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

+ 5
- 0
src/conf.cpp Ver arquivo

@@ -29,6 +29,7 @@ Configuration::Configuration(std::string filePath, bool mandatory) {
name = line.substr(0, delimiterPos);
value = line.substr(delimiterPos + 1);
data[name] = value;
// TODO: add another map of string to bools to mark wheter the option was used or not
}
}
} else {
@@ -44,6 +45,10 @@ void Configuration::show(void) {
}

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

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

+ 6
- 1
src/conf.h Ver arquivo

@@ -29,8 +29,13 @@ class Configuration {
public:
Configuration(std::string = "", bool = false);
~Configuration();

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

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

+ 4
- 4
src/main.cpp Ver arquivo

@@ -35,18 +35,18 @@ int main(int argc, char **argv) {
Player *player = nullptr;
Configuration conf;
conf.show();
// 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();
dealer = new Blackjack(conf);
if (isatty(1)) {
player = new Tty();
player = new Tty(conf);
} else {
player = new StdInOut();
}
// TODO: player strategy from file
dealer->nextAction = DealerAction::StartNewHand;
while (!dealer->finished()) {

+ 9
- 1
src/tty.cpp Ver arquivo

@@ -6,10 +6,18 @@
#include <readline/history.h>
#endif

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

+ 1
- 1
src/tty.h Ver arquivo

@@ -4,7 +4,7 @@

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

Carregando…
Cancelar
Salvar