Bladeren bron

verbosity

master
gtheler 5 jaren geleden
bovenliggende
commit
49fc507a1c
3 gewijzigde bestanden met toevoegingen van 55 en 42 verwijderingen
  1. +13
    -5
      src/base.h
  2. +37
    -37
      src/blackjack.cpp
  3. +5
    -0
      src/tty.cpp

+ 13
- 5
src/base.h Bestand weergeven

@@ -207,8 +207,6 @@ class Player {
PlayerActionRequired actionRequired = PlayerActionRequired::None;
PlayerActionTaken actionTaken = PlayerActionTaken::None;
bool bustedAllHands = false;

unsigned int currentSplits = 0;
@@ -232,7 +230,8 @@ class Player {
unsigned int losses = 0;
// TODO: blackjack_pushes?
unsigned int flat_bet = 0;
bool verbose = false;
bool flat_bet = false;
bool no_insurance = false;
bool always_insure = false;
@@ -266,6 +265,13 @@ class Dealer {
virtual void deal(Player *) = 0;
virtual unsigned int drawCard(Hand * = nullptr) = 0;
virtual int process(Player *) = 0;
void info(Player *player, Info msg, int p1 = 0, int p2 = 0) {
if (player->verbose) {
player->info(msg, p1, p2);
}
return;
}

bool finished(void) {
return done;
@@ -275,14 +281,16 @@ class Dealer {
return (done = d);
}
bool done = false;
DealerAction nextAction = DealerAction::None;
// TODO: most of the games will have a single element, but maybe
// there are games where the dealer has more than one hand
// std::list <Hand> hands;
Hand hand;

private:
bool done = false;

};

#endif

+ 37
- 37
src/blackjack.cpp Bestand weergeven

@@ -122,7 +122,7 @@ void Blackjack::deal(Player *player) {
player->currentSplits = 0;
if (lastPass) {
player->info(Info::Shuffle);
info(player, Info::Shuffle);
// shuffle the cards
shuffle();
@@ -144,7 +144,7 @@ void Blackjack::deal(Player *player) {

}

player->info(Info::NewHand, n_hand, 1e3*player->bankroll);
info(player, Info::NewHand, n_hand, 1e3*player->bankroll);
return;
break;
@@ -160,19 +160,19 @@ void Blackjack::deal(Player *player) {
player->total_money_waged += player->currentHand->bet;

playerFirstCard = drawCard(&(*player->currentHand));
player->info(Info::CardPlayer, playerFirstCard);
info(player, Info::CardPlayer, playerFirstCard);
// step 4. show dealer's upcard
upCard = drawCard(&hand);
player->info(Info::CardDealer, upCard);
info(player, Info::CardDealer, upCard);

// step 5. deal the second card to each player
playerSecondCard = drawCard(&(*player->currentHand));
player->info(Info::CardPlayer, playerSecondCard);
info(player, Info::CardPlayer, playerSecondCard);
// step 6. deal the dealer's hole card
holeCard = drawCard(&hand);
player->info(Info::CardDealer);
info(player, Info::CardDealer);

// step 7.a. if the upcard is an ace ask for insurance
if (card[upCard].value == 11) {
@@ -216,25 +216,25 @@ void Blackjack::deal(Player *player) {
// step 8. check if there are any blackjack
playerBlackack = player->currentHand->blackjack();
if (hand.blackjack()) {
player->info(Info::CardDealerRevealsHole, holeCard);
player->info(Info::DealerBlackjack);
info(player, Info::CardDealerRevealsHole, holeCard);
info(player, Info::DealerBlackjack);
player->blackjacksDealer++;

if (player->currentHand->insured) {
player->info(Info::PlayerWinsInsurance, 1e3*player->currentHand->bet);
info(player, Info::PlayerWinsInsurance, 1e3*player->currentHand->bet);
player->current_result += player->currentHand->bet;
player->bankroll += player->currentHand->bet;
player->winsInsured++;
}

if (playerBlackack) {
player->info(Info::PlayerBlackjackAlso);
player->info(Info::PlayerPushes, 1e3*player->currentHand->bet);
info(player, Info::PlayerBlackjackAlso);
info(player, Info::PlayerPushes, 1e3*player->currentHand->bet);
player->blackjacksPlayer++;
player->pushes++;
} else {
player->info(Info::PlayerLosses, 1e3*player->currentHand->bet);
info(player, Info::PlayerLosses, 1e3*player->currentHand->bet);
player->current_result -= player->currentHand->bet;
player->bankroll -= player->currentHand->bet;
if (player->bankroll < player->worst_bankroll) {
@@ -252,7 +252,7 @@ void Blackjack::deal(Player *player) {
player->bankroll += blackjack_pays * player->currentHand->bet;
player->blackjacksPlayer++;
player->info(Info::PlayerWins, 1e3 * blackjack_pays*player->currentHand->bet);
info(player, Info::PlayerWins, 1e3 * blackjack_pays*player->currentHand->bet);
player->wins++;
player->winsBlackjack++;

@@ -263,7 +263,7 @@ void Blackjack::deal(Player *player) {
} else {
// only if the dealer had the chance to have a blackjack we say "no_blackjacks"
if (card[upCard].value == 10 || card[upCard].value == 11) {
player->info(Info::NoBlackjacks);
info(player, Info::NoBlackjacks);
}
nextAction = DealerAction::AskForPlay;
@@ -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));
player->info(Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard);

if (std::abs(player->currentHand->total()) == 21) {
player->actionRequired = PlayerActionRequired::None;
@@ -295,16 +295,16 @@ void Blackjack::deal(Player *player) {
}
} else {
// assume the player busted in all the hands
player->bustedAllHands = true;
bool bustedAllHands = true;
for (auto playerHand : player->hands) {
// if she did not bust, set false
if (playerHand.busted() == false) {
player->bustedAllHands = false;
bustedAllHands = false;
}
}

if (player->bustedAllHands) {
player->info(Info::CardDealerRevealsHole, holeCard);
if (bustedAllHands) {
info(player, Info::CardDealerRevealsHole, holeCard);
player->actionRequired = PlayerActionRequired::None;
nextAction = DealerAction::StartNewHand;
@@ -319,23 +319,23 @@ void Blackjack::deal(Player *player) {
case DealerAction::HitDealerHand:
player->info(Info::CardDealerRevealsHole, holeCard);
info(player, Info::CardDealerRevealsHole, holeCard);

// hit while count is less than 17 (or equal to soft 17 if hit_soft_17 is true)
dealerTotal = hand.total();
while ((std::abs(dealerTotal) < 17 || (hit_soft_17 && dealerTotal == -17)) && hand.busted() == 0) {
unsigned int dealerCard = drawCard(&hand);
player->info(Info::CardDealer, dealerCard);
info(player, Info::CardDealer, dealerCard);
dealerTotal = hand.total();
}

if (hand.busted()) {
player->info(Info::DealerBusts, dealerTotal);
info(player, Info::DealerBusts, dealerTotal);
player->bustsDealer++;
for (auto playerHand : player->hands) {
if (playerHand.busted() == false) {
player->info(Info::PlayerWins, 1e3*playerHand.bet);
info(player, Info::PlayerWins, 1e3*playerHand.bet);
player->current_result += playerHand.bet;
player->bankroll += playerHand.bet;
player->wins++;
@@ -349,7 +349,7 @@ void Blackjack::deal(Player *player) {
if (dealerTotal > playerTotal) {
player->info(Info::PlayerLosses, 1e3*playerHand.bet, playerTotal);
info(player, Info::PlayerLosses, 1e3*playerHand.bet, playerTotal);
player->bankroll -= playerHand.bet;
if (player->bankroll < player->worst_bankroll) {
player->worst_bankroll = player->bankroll;
@@ -358,12 +358,12 @@ void Blackjack::deal(Player *player) {
} else if (dealerTotal == playerTotal) {
player->info(Info::PlayerPushes, 1e3*playerHand.bet);
info(player, Info::PlayerPushes, 1e3*playerHand.bet);
player->pushes++;
} else {
player->info(Info::PlayerWins, 1e3*playerHand.bet, playerTotal);
info(player, Info::PlayerWins, 1e3*playerHand.bet, playerTotal);
player->current_result += playerHand.bet;
player->bankroll += playerHand.bet;
player->wins++;
@@ -419,7 +419,7 @@ int Blackjack::process(Player *player) {
///ig+help+detail A succinct help message is written on the standard output.
///ig+help+detail This command makes sense only when issued by a human player.
case PlayerActionTaken::Help:
player->info(Info::Help);
info(player, Info::Help);
return 0;
break;
@@ -432,13 +432,13 @@ int Blackjack::process(Player *player) {
case PlayerActionTaken::Bet:
// TODO: bet = 0 -> wonging
if (player->currentBet == 0) {
player->info(Info::InvalidBet, player->currentBet);
info(player, Info::InvalidBet, player->currentBet);
return 0;
} else if (player->currentBet < 0) {
player->info(Info::InvalidBet, player->currentBet);
info(player, Info::InvalidBet, player->currentBet);
return 0;
} else if (max_bet != 0 && player->currentBet > max_bet) {
player->info(Info::InvalidBet, player->currentBet);
info(player, Info::InvalidBet, player->currentBet);
return 0;
} else {
// ok, valid bet
@@ -499,10 +499,10 @@ int Blackjack::process(Player *player) {

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

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

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

// aces get dealt only one card
// also, if the player gets 21 then we move on to the next hand
if (card[*player->currentHand->cards.begin()].value == 11 || std::abs(player->currentHand->total()) == 21) {
if (++player->currentHand != player->hands.end()) {
player->info(Info::PlayerNextHand, (*player->currentHand).id);
info(player, Info::PlayerNextHand, (*player->currentHand).id);
playerCard = drawCard(&(*player->currentHand));
player->info(Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard);

// 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,10 +604,10 @@ int Blackjack::process(Player *player) {
///ip+hit+detail
///ip+hit+detail This command can be abbreviated as `h`.
playerCard = drawCard(&(*player->currentHand));
player->info(Info::CardPlayer, playerCard);
info(player, Info::CardPlayer, playerCard);

if (player->currentHand->busted()) {
player->info(Info::PlayerLosses, 1e3*player->currentHand->bet);
info(player, Info::PlayerLosses, 1e3*player->currentHand->bet);
player->current_result -= player->currentHand->bet;
player->bankroll -= player->currentHand->bet;
player->bustsPlayer++;

+ 5
- 0
src/tty.cpp Bestand weergeven

@@ -59,6 +59,11 @@ Tty::Tty(Configuration &conf) {
commands.push_back("quit");
}
verbose = true;
if (conf.exists("verbose")) {
conf.set(&verbose, {"verbose"});
}

if (conf.exists("color")) {
conf.set(&color, {"color"});
}

Laden…
Annuleren
Opslaan