Browse Source

render hands on the player's side only (except for "table" command)

master
gtheler 5 years ago
parent
commit
896c51e4a0
10 changed files with 173 additions and 21 deletions
  1. +22
    -0
      src/base.cpp
  2. +4
    -11
      src/base.h
  3. +6
    -6
      src/blackjack.cpp
  4. +22
    -0
      src/cards.cpp
  5. +22
    -0
      src/conf.cpp
  6. +1
    -1
      src/conf.h
  7. +22
    -0
      src/stdinout.cpp
  8. +22
    -0
      src/stdinout.h
  9. +30
    -3
      src/tty.cpp
  10. +22
    -0
      src/tty.h

+ 22
- 0
src/base.cpp View File

/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - base classes
*
* Copyright (C) 2020 jeremy theler
*
* This file is part of Libre Blackjack.
*
* Libre Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libre Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/

#include <iostream> #include <iostream>
#include "base.h" #include "base.h"



+ 4
- 11
src/base.h View File

/*------------ -------------- -------- --- ----- --- -- - - /*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - standard blackjack dealer
* Libre Blackjack - base classes
* *
* Copyright (C) 2020 jeremy theler * Copyright (C) 2020 jeremy theler
* *
Player(Player &&) = delete; Player(Player &&) = delete;
Player(const Player &&) = delete; Player(const Player &&) = delete;


// TODO: public or getter/setter?
/*
PlayerAction getNextAction() {
return nextAction;
}
void setNextAction(PlayerAction a) {
nextAction = a;
}
*/
virtual int play() = 0; virtual int play() = 0;
virtual void info(Info = Info::None, int = 0) = 0; virtual void info(Info = Info::None, int = 0) = 0;
std::list<PlayerHand> hands; std::list<PlayerHand> hands;
std::list<PlayerHand>::iterator currentHand; std::list<PlayerHand>::iterator currentHand;

DealerHand dealerHand;
}; };


class Dealer { class Dealer {

+ 6
- 6
src/blackjack.cpp View File

player->actionRequired = PlayerActionRequired::Play; player->actionRequired = PlayerActionRequired::Play;
nextAction = DealerAction::AskForPlay; nextAction = DealerAction::AskForPlay;
hand.render(hand.holeCardShown);
player->currentHand->render();
// hand.render(hand.holeCardShown);
// player->currentHand->render();
std::cout << "dealer upcard is " << card[upCard].utf8() << std::endl; std::cout << "dealer upcard is " << card[upCard].utf8() << std::endl;
std::cout << "your total is " << player->currentHand->total() << std::endl; std::cout << "your total is " << player->currentHand->total() << std::endl;
} else { } else {
std::cout << "card_player " << card[playerCard].utf8() << std::endl; std::cout << "card_player " << card[playerCard].utf8() << std::endl;
} }
player->currentHand->render();
// player->currentHand->render();


if (player->currentHand->total() == 21) { if (player->currentHand->total() == 21) {
player->actionRequired = PlayerActionRequired::None; player->actionRequired = PlayerActionRequired::None;
std::cout << "card_dealer_hole " << card[holeCard].utf8() << std::endl; std::cout << "card_dealer_hole " << card[holeCard].utf8() << std::endl;
hand.holeCardShown = true; hand.holeCardShown = true;
std::cout << "dealer_hand" << std::endl; std::cout << "dealer_hand" << std::endl;
hand.render(hand.holeCardShown);
// hand.render(hand.holeCardShown);
// TODO: no tengo que sacarle todo el dinero? // TODO: no tengo que sacarle todo el dinero?
std::cout << "card_dealer_hole" << card[holeCard].utf8() << std::endl; std::cout << "card_dealer_hole" << card[holeCard].utf8() << std::endl;
hand.holeCardShown = true; hand.holeCardShown = true;


hand.render(hand.holeCardShown);
// hand.render(hand.holeCardShown);


// TODO: print "soft" // TODO: print "soft"
std::cout << "dealer_count " << hand.total() << std::endl; std::cout << "dealer_count " << hand.total() << std::endl;
while (((abs(dealerTotal) < 17 || (hit_soft_17 && dealerTotal == -17))) && hand.busted() == 0) { while (((abs(dealerTotal) < 17 || (hit_soft_17 && dealerTotal == -17))) && hand.busted() == 0) {
unsigned int dealerCard = drawCard(&hand); unsigned int dealerCard = drawCard(&hand);
std::cout << "card_dealer " << card[dealerCard].utf8() << std::endl; std::cout << "card_dealer " << card[dealerCard].utf8() << std::endl;
hand.render(hand.holeCardShown);
// hand.render(hand.holeCardShown);
dealerTotal = abs(hand.total()); dealerTotal = abs(hand.total());
std::cout << "dealer_count " << dealerTotal << std::endl; std::cout << "dealer_count " << dealerTotal << std::endl;

+ 22
- 0
src/cards.cpp View File

/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - fifty-two-deck cards
*
* Copyright (C) 2020 jeremy theler
*
* This file is part of Libre Blackjack.
*
* Libre Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libre Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/

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


static std::string TJQK[4] = {"T", "J", "Q", "K"}; static std::string TJQK[4] = {"T", "J", "Q", "K"};

+ 22
- 0
src/conf.cpp View File

/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - configuration handling
*
* Copyright (C) 2020 jeremy theler
*
* This file is part of Libre Blackjack.
*
* Libre Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libre Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/

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


#include <iostream> #include <iostream>

+ 1
- 1
src/conf.h View File

/*------------ -------------- -------- --- ----- --- -- - - /*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - standard blackjack dealer
* Libre Blackjack - configuration handling
* *
* Copyright (C) 2020 jeremy theler * Copyright (C) 2020 jeremy theler
* *

+ 22
- 0
src/stdinout.cpp View File

/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - stdio player
*
* Copyright (C) 2020 jeremy theler
*
* This file is part of Libre Blackjack.
*
* Libre Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libre Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/

#include <iostream> #include <iostream>


#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE

+ 22
- 0
src/stdinout.h View File

/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - stdio player
*
* Copyright (C) 2020 jeremy theler
*
* This file is part of Libre Blackjack.
*
* Libre Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libre Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/

#ifndef STDINOUT_H #ifndef STDINOUT_H
#define STDINOUT_H #define STDINOUT_H
#include "blackjack.h" #include "blackjack.h"

+ 30
- 3
src/tty.cpp View File

/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - tty interactive player
*
* Copyright (C) 2020 jeremy theler
*
* This file is part of Libre Blackjack.
*
* Libre Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libre Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/

#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <thread> #include <thread>
conf.set(&flat_bet, {"flat_bet", "flatbet"}); conf.set(&flat_bet, {"flat_bet", "flatbet"});
conf.set(&no_insurance, {"no_insurance", "dont_insure"}); conf.set(&no_insurance, {"no_insurance", "dont_insure"});


#ifdef HAVE_LIBREADLINE
// TODO: check conf for colors
prompt = cyan + " > " + reset; prompt = cyan + " > " + reset;
#endif
} }


void Tty::info(Info msg, int intData) { void Tty::info(Info msg, int intData) {
std::string s; std::string s;
// TODO: choose utf8 or other representation
switch (msg) { switch (msg) {
case Info::NewHand: case Info::NewHand:
// s = "new_hand"; // s = "new_hand";
s = "Starting new hand #" + std::to_string(intData); s = "Starting new hand #" + std::to_string(intData);
dealerHand.cards.clear();
break; break;
case Info::Shuffle: case Info::Shuffle:
// s = "shuffle"; // s = "shuffle";
case Info::CardDealerUp: case Info::CardDealerUp:
// s = "card_dealer_up"; // s = "card_dealer_up";
s = "Dealer's up card " + card[intData].utf8(); s = "Dealer's up card " + card[intData].utf8();
dealerHand.cards.push_back(intData);
break; break;
case Info::CardPlayerSecond: case Info::CardPlayerSecond:
// s = "card_player_second"; // s = "card_player_second";
case Info::CardDealerHoleRevealed: case Info::CardDealerHoleRevealed:
// s = "card_dealer_hole"; // s = "card_dealer_hole";
s = "Dealer's hole card was " + card[intData].utf8(); s = "Dealer's hole card was " + card[intData].utf8();
dealerHand.cards.push_back(intData);
break; break;
case Info::DealerBlackjack: case Info::DealerBlackjack:
// s = "dealer_blackjack"; // s = "dealer_blackjack";
if (msg == Info::CardDealerHoleDealt) { if (msg == Info::CardDealerHoleDealt) {
// hand.render(hand.holeCardShown);
dealerHand.render();
currentHand->render(); currentHand->render();
} }

+ 22
- 0
src/tty.h View File

/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - tty interactive player
*
* Copyright (C) 2020 jeremy theler
*
* This file is part of Libre Blackjack.
*
* Libre Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libre Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/

#ifndef TTY_H #ifndef TTY_H
#define TTY_H #define TTY_H
#include "blackjack.h" #include "blackjack.h"

Loading…
Cancel
Save