Sfoglia il codice sorgente

fixed stuff

master
gtheler 5 anni fa
parent
commit
48834c7741
2 ha cambiato i file con 38 aggiunte e 22 eliminazioni
  1. +13
    -4
      src/blackjack.cpp
  2. +25
    -18
      src/tty.cpp

+ 13
- 4
src/blackjack.cpp Vedi File

@@ -80,7 +80,9 @@ void Blackjack::deal(void) {
bool playerBlackack = false;
// let's start by assuming the player does not need to do anything
player->actionRequired = Libreblackjack::PlayerActionRequired::None;

std::list<PlayerHand>::iterator playerHand;
switch(nextAction) {
// -------------------------------------------------------------------------
case Libreblackjack::DealerAction::StartNewHand:
@@ -109,8 +111,8 @@ void Blackjack::deal(void) {
hand.cards.clear();

// erase all the player's hands, create one, add and make it the current one
for (auto playerHand : playerInfo.hands) {
playerHand.cards.clear();
for (playerHand = playerInfo.hands.begin(); playerHand != playerInfo.hands.end(); ++playerHand) {
playerHand->cards.clear();
}
playerInfo.hands.clear();
playerInfo.hands.push_back(std::move(PlayerHand()));
@@ -534,6 +536,10 @@ int Blackjack::process(void) {
// TODO: choose through conf
// TODO: check bankroll to see if player can split
if (playerInfo.currentSplits < 3 && playerInfo.currentHand->cards.size() == 2 && card[firstCard].value == card[secondCard].value) {
// tell the player the split is valid
info(Libreblackjack::Info::PlayerSplitOk, playerInfo.currentHand->id);
// mark that we split to put ids in the hands and to limi the number of spltis
playerInfo.currentSplits++;

@@ -557,6 +563,9 @@ int Blackjack::process(void) {
// add the new hand to the list of hands
playerInfo.hands.push_back(std::move(newHand));

// tell the player what the ids are
info(Libreblackjack::Info::PlayerSplitIds, playerInfo.currentHand->id, newHand.id);
// deal a card to the first hand
playerCard = drawCard(&(*playerInfo.currentHand));
info(Libreblackjack::Info::CardPlayer, playerCard, playerInfo.currentHand->id);
@@ -591,7 +600,7 @@ int Blackjack::process(void) {
}
} else {

std::cout << "cannot_split" << std::endl;
info(Libreblackjack::Info::PlayerSplitInvalid);
return -1;
}

+ 25
- 18
src/tty.cpp Vedi File

@@ -188,34 +188,43 @@ void Tty::info(Libreblackjack::Info msg, int p1, int p2) {
case Libreblackjack::Info::PlayerSplitInvalid:
// s = "player_split_invalid";
s = "Cannot split";
render = true;
break;

case Libreblackjack::Info::PlayerSplitOk:
// s = "player_split_ok";
s = "Splitting hand" + ((p1 != 0)?(" #" + std::to_string(p1)):"");
handToSplit = p1;
render = true;
break;

case Libreblackjack::Info::PlayerSplitIds:

// TODO: check if the hand is found
for (auto hand = hands.begin(); hand != hands.end(); ++currentHand) {
if (hand->id == handToSplit) {
hand->id = p1;
cardToSplit = hand.back();
hand.pop_back();
break;
{
bool found = false;
std::list<PlayerHand>::iterator hand;
for (hand = hands.begin(); hand != hands.end(); ++hand) {
if (hand->id == handToSplit) {
found = true;
hand->id = p1;
cardToSplit = *(++(hand->cards.begin()));
hand->cards.pop_back();
break;
}
}
if (found == false) {
exit(0);
}
}
// create a new hand
PlayerHand newHand;
newHand.id = playerInfo.hands.size() + 1;
newHand.bet = playerInfo.currentHand->bet;
for (auto hand : hands) {
std::cout << hand.id << " " << hand.cards.size() << std::endl;
}
// create a new hand
PlayerHand newHand;
newHand.id = p2;
newHand.cards.push_back(cardToSplit);
hands.push_back(std::move(newHand));
}
currentHandId = p1;
render = true;
break;
@@ -431,9 +440,7 @@ void Tty::renderHand(Hand *hand, bool current) {
std::cout << " _____ ";
}
std::cout << std::endl;
// std::cout << "hand id = " << hand->id << std::endl;
for (auto c : hand->cards) {
if (color && (card[c].suit == Libreblackjack::Suit::Diamonds || card[c].suit == Libreblackjack::Suit::Hearts)) {
ansiColor = red;

Loading…
Annulla
Salva