瀏覽代碼

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

master
gtheler 5 年之前
父節點
當前提交
896c51e4a0
共有 10 個文件被更改,包括 173 次插入21 次删除
  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 查看文件

@@ -1,3 +1,25 @@
/*------------ -------------- -------- --- ----- --- -- - -
* 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 "base.h"


+ 4
- 11
src/base.h 查看文件

@@ -1,5 +1,5 @@
/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - standard blackjack dealer
* Libre Blackjack - base classes
*
* Copyright (C) 2020 jeremy theler
*
@@ -196,16 +196,6 @@ class Player {
Player(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 void info(Info = Info::None, int = 0) = 0;
@@ -250,6 +240,9 @@ class Player {
std::list<PlayerHand> hands;
std::list<PlayerHand>::iterator currentHand;

DealerHand dealerHand;
};

class Dealer {

+ 6
- 6
src/blackjack.cpp 查看文件

@@ -283,8 +283,8 @@ void Blackjack::deal(Player *player) {
player->actionRequired = PlayerActionRequired::Play;
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 << "your total is " << player->currentHand->total() << std::endl;
@@ -301,7 +301,7 @@ void Blackjack::deal(Player *player) {
} else {
std::cout << "card_player " << card[playerCard].utf8() << std::endl;
}
player->currentHand->render();
// player->currentHand->render();

if (player->currentHand->total() == 21) {
player->actionRequired = PlayerActionRequired::None;
@@ -327,7 +327,7 @@ void Blackjack::deal(Player *player) {
std::cout << "card_dealer_hole " << card[holeCard].utf8() << std::endl;
hand.holeCardShown = true;
std::cout << "dealer_hand" << std::endl;
hand.render(hand.holeCardShown);
// hand.render(hand.holeCardShown);
// TODO: no tengo que sacarle todo el dinero?
@@ -347,7 +347,7 @@ void Blackjack::deal(Player *player) {
std::cout << "card_dealer_hole" << card[holeCard].utf8() << std::endl;
hand.holeCardShown = true;

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

// TODO: print "soft"
std::cout << "dealer_count " << hand.total() << std::endl;
@@ -357,7 +357,7 @@ void Blackjack::deal(Player *player) {
while (((abs(dealerTotal) < 17 || (hit_soft_17 && dealerTotal == -17))) && hand.busted() == 0) {
unsigned int dealerCard = drawCard(&hand);
std::cout << "card_dealer " << card[dealerCard].utf8() << std::endl;
hand.render(hand.holeCardShown);
// hand.render(hand.holeCardShown);
dealerTotal = abs(hand.total());
std::cout << "dealer_count " << dealerTotal << std::endl;

+ 22
- 0
src/cards.cpp 查看文件

@@ -1,3 +1,25 @@
/*------------ -------------- -------- --- ----- --- -- - -
* 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"

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

+ 22
- 0
src/conf.cpp 查看文件

@@ -1,3 +1,25 @@
/*------------ -------------- -------- --- ----- --- -- - -
* 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 <iostream>

+ 1
- 1
src/conf.h 查看文件

@@ -1,5 +1,5 @@
/*------------ -------------- -------- --- ----- --- -- - -
* Libre Blackjack - standard blackjack dealer
* Libre Blackjack - configuration handling
*
* Copyright (C) 2020 jeremy theler
*

+ 22
- 0
src/stdinout.cpp 查看文件

@@ -1,3 +1,25 @@
/*------------ -------------- -------- --- ----- --- -- - -
* 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>

#ifdef HAVE_LIBREADLINE

+ 22
- 0
src/stdinout.h 查看文件

@@ -1,3 +1,25 @@
/*------------ -------------- -------- --- ----- --- -- - -
* 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
#define STDINOUT_H
#include "blackjack.h"

+ 30
- 3
src/tty.cpp 查看文件

@@ -1,3 +1,25 @@
/*------------ -------------- -------- --- ----- --- -- - -
* 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 <cstring>
#include <thread>
@@ -17,18 +39,21 @@ Tty::Tty(Configuration &conf) {
conf.set(&flat_bet, {"flat_bet", "flatbet"});
conf.set(&no_insurance, {"no_insurance", "dont_insure"});

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

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

+ 22
- 0
src/tty.h 查看文件

@@ -1,3 +1,25 @@
/*------------ -------------- -------- --- ----- --- -- - -
* 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
#define TTY_H
#include "blackjack.h"

Loading…
取消
儲存