ソースを参照

fixed stuff

master
gtheler 5年前
コミット
48834c7741
2個のファイルの変更38行の追加22行の削除
  1. +13
    -4
      src/blackjack.cpp
  2. +25
    -18
      src/tty.cpp

+ 13
- 4
src/blackjack.cpp ファイルの表示

bool playerBlackack = false; bool playerBlackack = false;
// let's start by assuming the player does not need to do anything // let's start by assuming the player does not need to do anything
player->actionRequired = Libreblackjack::PlayerActionRequired::None; player->actionRequired = Libreblackjack::PlayerActionRequired::None;

std::list<PlayerHand>::iterator playerHand;
switch(nextAction) { switch(nextAction) {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
case Libreblackjack::DealerAction::StartNewHand: case Libreblackjack::DealerAction::StartNewHand:
hand.cards.clear(); hand.cards.clear();


// erase all the player's hands, create one, add and make it the current one // 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.clear();
playerInfo.hands.push_back(std::move(PlayerHand())); playerInfo.hands.push_back(std::move(PlayerHand()));
// TODO: choose through conf // TODO: choose through conf
// TODO: check bankroll to see if player can split // TODO: check bankroll to see if player can split
if (playerInfo.currentSplits < 3 && playerInfo.currentHand->cards.size() == 2 && card[firstCard].value == card[secondCard].value) { 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 // mark that we split to put ids in the hands and to limi the number of spltis
playerInfo.currentSplits++; playerInfo.currentSplits++;


// add the new hand to the list of hands // add the new hand to the list of hands
playerInfo.hands.push_back(std::move(newHand)); 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 // deal a card to the first hand
playerCard = drawCard(&(*playerInfo.currentHand)); playerCard = drawCard(&(*playerInfo.currentHand));
info(Libreblackjack::Info::CardPlayer, playerCard, playerInfo.currentHand->id); info(Libreblackjack::Info::CardPlayer, playerCard, playerInfo.currentHand->id);
} }
} else { } else {


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

+ 25
- 18
src/tty.cpp ファイルの表示

case Libreblackjack::Info::PlayerSplitInvalid: case Libreblackjack::Info::PlayerSplitInvalid:
// s = "player_split_invalid"; // s = "player_split_invalid";
s = "Cannot split"; s = "Cannot split";
render = true;
break; break;


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


case Libreblackjack::Info::PlayerSplitIds: 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; render = true;
break; break;
std::cout << " _____ "; std::cout << " _____ ";
} }
std::cout << std::endl; std::cout << std::endl;
// std::cout << "hand id = " << hand->id << std::endl;
for (auto c : hand->cards) { for (auto c : hand->cards) {
if (color && (card[c].suit == Libreblackjack::Suit::Diamonds || card[c].suit == Libreblackjack::Suit::Hearts)) { if (color && (card[c].suit == Libreblackjack::Suit::Diamonds || card[c].suit == Libreblackjack::Suit::Hearts)) {
ansiColor = red; ansiColor = red;

読み込み中…
キャンセル
保存