gtheler 5 lat temu
rodzic
commit
256a8e1972
5 zmienionych plików z 22 dodań i 35 usunięć
  1. +2
    -1
      blackjack.conf
  2. +2
    -0
      src/base.h
  3. +5
    -5
      src/blackjack.cpp
  4. +12
    -28
      src/tty.cpp
  5. +1
    -1
      src/tty.h

+ 2
- 1
blackjack.conf Wyświetl plik

@@ -1,4 +1,5 @@
; flat_bet = 1
; arranged_cards = 3,8,3,13,4,13,11,7
arranged_cards = 3,8,16
rng_seed = 5
; delay = 0


+ 2
- 0
src/base.h Wyświetl plik

@@ -208,6 +208,7 @@ class Player {
PlayerActionRequired actionRequired = PlayerActionRequired::None;
PlayerActionTaken actionTaken = PlayerActionTaken::None;

// TODO: one for the dealer and one for the player
unsigned int currentSplits = 0;
unsigned int currentBet = 0;
@@ -245,6 +246,7 @@ class Player {
std::list<PlayerHand> hands;
std::list<PlayerHand>::iterator currentHand;
std::size_t currentHandId = 0;

Hand dealerHand;

+ 5
- 5
src/blackjack.cpp Wyświetl plik

@@ -282,7 +282,7 @@ void Blackjack::deal(Player *player) {
// see if we finished all the player's hands
if (++player->currentHand != player->hands.end()) {
unsigned int playerCard = drawCard(&(*player->currentHand));
info(player, Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard, player->currentHand->id);

if (std::abs(player->currentHand->total()) == 21) {
player->actionRequired = PlayerActionRequired::None;
@@ -499,7 +499,7 @@ int Blackjack::process(Player *player) {

playerCard = drawCard(&(*player->currentHand));
unsigned int playerTotal = player->currentHand->total();
info(player, Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard, player->currentHand->id);

if (player->currentHand->busted()) {
info(player, Info::PlayerLosses, 1e3*player->currentHand->bet, playerTotal);
@@ -559,7 +559,7 @@ int Blackjack::process(Player *player) {

// deal a card to the first hand
playerCard = drawCard(&(*player->currentHand));
info(player, Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard, player->currentHand->id);

// aces get dealt only one card
// also, if the player gets 21 then we move on to the next hand
@@ -567,7 +567,7 @@ int Blackjack::process(Player *player) {
if (++player->currentHand != player->hands.end()) {
info(player, Info::PlayerNextHand, (*player->currentHand).id);
playerCard = drawCard(&(*player->currentHand));
info(player, Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard, player->currentHand->id);

// if the player got an ace or 21 again, we are done
if (card[*player->currentHand->cards.begin()].value == 11 || std::abs(player->currentHand->total()) == 21) {
@@ -604,7 +604,7 @@ int Blackjack::process(Player *player) {
///ip+hit+detail
///ip+hit+detail This command can be abbreviated as `h`.
playerCard = drawCard(&(*player->currentHand));
info(player, Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard, player->currentHand->id);

if (player->currentHand->busted()) {
info(player, Info::PlayerLosses, 1e3*player->currentHand->bet);

+ 12
- 28
src/tty.cpp Wyświetl plik

@@ -120,20 +120,10 @@ void Tty::info(Info msg, int p1, int p2) {
break;
case Info::CardPlayer:
switch (currentHand->cards.size()) {
case 1:
// s = "card_player_first";
s = "Player's first card is " + card[p1].utf8();
break;
case 2:
// s = "card_player_second";
s = "Player's second card is " + card[p1].utf8();
break;
default:
// s = "card_player";
s = "Player's card is " + card[p1].utf8();
break;
}
// s = "card_player";
currentHandId = p2;
s = "Player's card" + ((p2 != 0)?(" in hand #"+std::to_string(p2)):"") + " is " + card[p1].utf8();
break;
break;
case Info::CardDealer:
@@ -209,17 +199,6 @@ void Tty::info(Info msg, int p1, int p2) {
s = "No blackjacks";
break;

/*
case Info::PlayerBustsAllHands:
// s = "player_busted_all_hands";
if (hands.size() == 1) {
s = "Player busted";
} else {
s = "Player busted all hands";
}
renderTable();
break;
*/
case Info::DealerBusts:
// s = "no_blackjacks";
s = "Dealer busts with " + std::to_string(p1);
@@ -342,7 +321,7 @@ int Tty::play() {
} else if (command == "s" || command == "stand") {
actionTaken = PlayerActionTaken::Stand;
} else if (command == "d" || command == "double") {
actionTaken = PlayerActionTaken::Stand;
actionTaken = PlayerActionTaken::Double;
} else if (command == "p" || command == "split" || command == "pair") {
actionTaken = PlayerActionTaken::Split;
} else {
@@ -383,14 +362,14 @@ void Tty::renderTable(void) {

std::cout << " -- Player's hand --------" << std::endl;
for (auto hand : hands) {
renderHand(&hand);
renderHand(&hand, (hand.id != 0) && (hand.id == currentHandId));
std::cout << " Total: " << ((hand.total() < 0)?"soft ":"") << std::abs(hand.total()) << std::endl;
}

return;
}

void Tty::renderHand(Hand *hand) {
void Tty::renderHand(Hand *hand, bool current) {

std::string ansiColor;
std::string ansiReset;
@@ -400,6 +379,8 @@ void Tty::renderHand(Hand *hand) {
}
std::cout << std::endl;
std::cout << "hand id = " << hand->id << std::endl;
for (auto c : hand->cards) {
if (color && (card[c].suit == Suit::Diamonds || card[c].suit == Suit::Hearts)) {
ansiColor = red;
@@ -441,6 +422,9 @@ void Tty::renderHand(Hand *hand) {
std::cout << "|#####| ";
}
}
if (current) {
std::cout << cyan << "<-- current hand" << reset;
}
std::cout << std::endl;
for (auto c : hand->cards) {

+ 1
- 1
src/tty.h Wyświetl plik

@@ -47,7 +47,7 @@ class Tty : public Player {
private:

void renderHand(Hand *);
void renderHand(Hand *, bool = false);
void renderTable(void);
#ifdef HAVE_LIBREADLINE

Ładowanie…
Anuluj
Zapisz