From bbdc5decaaf6e66987980c81a4bc688558039377 Mon Sep 17 00:00:00 2001
From: spiasecki <spiasecki@student.ethz.ch>
Date: Fri, 27 May 2022 11:59:10 +0200
Subject: [PATCH] Cleanup + final fix in get_points()

---
 source/client/panels/BetPanel.cpp        |  4 ++--
 source/general/game_state/game_state.cpp | 13 -------------
 source/general/game_state/hand.cpp       | 17 +++++++++++------
 source/general/game_state/player.cpp     |  2 --
 source/general/game_state/shoe.cpp       |  5 +++--
 5 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/source/client/panels/BetPanel.cpp b/source/client/panels/BetPanel.cpp
index 037059f..7f4bb99 100644
--- a/source/client/panels/BetPanel.cpp
+++ b/source/client/panels/BetPanel.cpp
@@ -16,8 +16,8 @@ BetPanel::BetPanel(wxWindow* parent, game_state* gameState, player* me) : wxPane
     }
 
     // color of background
-    wxColor lightGreen = wxColor(210, 210, 210);
-    this->SetBackgroundColour(lightGreen);
+    wxColor lightGray = wxColor(210, 210, 210);
+    this->SetBackgroundColour(lightGray);
 
     wxBoxSizer* verticalLayout = new wxBoxSizer(wxVERTICAL);
 
diff --git a/source/general/game_state/game_state.cpp b/source/general/game_state/game_state.cpp
index d44cf5b..3fa4833 100644
--- a/source/general/game_state/game_state.cpp
+++ b/source/general/game_state/game_state.cpp
@@ -125,11 +125,9 @@ bool game_state::everyone_finished() const {
     unsigned int s = _players.size();
     for(unsigned int i = 0; i < s; ++i) {
         if(!(_players[i]->has_finished_turn()) && !(_players[i]->is_broke())){
-            std::cout << "Player " << i << " not finished!" << std::endl << std::flush;
             return false;
         }
     }
-    std::cout << "Everyone finished" << std::endl << std::flush;
     return true;
 }
 
@@ -288,8 +286,6 @@ bool game_state::stand(player* player, std::string& err) {
     }
 }
 
-//TODO: makes bets for everyone before the people actually start the round
-//TODO: other cases to take into account?
 bool game_state::make_bet(player* player, int bet_size, std::string& err) {
     if(!player->is_broke()) {
         player->make_bet(bet_size, err);
@@ -316,8 +312,6 @@ void game_state::update_current_player(std::string& err) {
 
 // end of round functions
 void game_state::wrap_up_round(std::string& err) {
-    //hardcoded dealer action
-
     int dealer_points = _dealers_hand->get_points(err);
 
     for(auto player : _players) {
@@ -347,13 +341,6 @@ void game_state::wrap_up_round(std::string& err) {
         //Flag that setup is required, so game_instance can perform it
         needs_setup = true;
     }
-// void game_state::compute_dealers_hand() {
-//     std::string err = "Problems drawing cards for dealer in the end";
-//     while(this->get_dealers_hand()->get_points(err)<= 16){
-//         this->get_shoe()->draw_card(this->get_dealers_hand(), err);
-//     }
-// }
-
 
 }
 #endif
diff --git a/source/general/game_state/hand.cpp b/source/general/game_state/hand.cpp
index 2ba001b..b4dddf7 100644
--- a/source/general/game_state/hand.cpp
+++ b/source/general/game_state/hand.cpp
@@ -46,10 +46,12 @@ bool hand::add_card(card* new_card, std::string &err) {
     return true;
 }
 
+// return how many points a hand is worth
 int hand::get_points(std::string &err) {
     int point_sum = 0;
     int ace_counter = 0;
 
+    // find sum of cards + number of aces
     for (auto card : _cards) {
         int value = card->get_value();
         if (value == 1) {
@@ -64,12 +66,15 @@ int hand::get_points(std::string &err) {
     }
 
     int result = 0;
-    //This assumes either all aces count 11 or all aces count 1
-    if (point_sum + 11*ace_counter <= 21){
-      result = point_sum + 11*ace_counter;
-    }
-    else{
-      result = point_sum + ace_counter;
+    // deal with the aces
+    if(ace_counter != 0) {
+        if (point_sum + 11 + ace_counter - 1 <= 21){
+            result = point_sum + 11 + ace_counter - 1;
+        } else {
+            result = point_sum + ace_counter;
+        }
+    } else {
+        result = point_sum;
     }
 
     return result;
diff --git a/source/general/game_state/player.cpp b/source/general/game_state/player.cpp
index e821e93..54e5a6d 100644
--- a/source/general/game_state/player.cpp
+++ b/source/general/game_state/player.cpp
@@ -77,7 +77,6 @@ std::string player::get_player_name() const noexcept {
     return this->_player_name->get_value();
 }
 
-//are we sure we need those
 void player::set_finished_turn() {
     this->_finished_turn->set_value(true);
 }
@@ -115,7 +114,6 @@ void player::wrap_up_round(int dealer_points, std::string& err) {
 }
 
 
-// TODO: add check if player already has a bet to throw error?
 bool player::make_bet(int bet_size, std::string &err) {
     if(bet_size > this->get_money()) {
         err = "bet_size is bigger than amount of money the player " + this->_player_name->get_value() + " has.";
diff --git a/source/general/game_state/shoe.cpp b/source/general/game_state/shoe.cpp
index 1ca57eb..c43a6c6 100644
--- a/source/general/game_state/shoe.cpp
+++ b/source/general/game_state/shoe.cpp
@@ -27,7 +27,7 @@ shoe::~shoe() {
     _cards.clear();
 }
 
-// implement this correctly
+// shuffle the shoe
 void shoe::shuffle() {
     std::shuffle(_cards.begin(), _cards.end(), std::mt19937(std::random_device()()));
 }
@@ -43,7 +43,7 @@ void shoe::setup_round(std::string &err) {
     }
     _cards.clear();
 
-    // add a fresh set of cards
+    // add a fresh set of cards (4 decks)
     for(int deck = 0; deck < 4; ++deck) {
         for(int suit = 0; suit < 4; ++suit) {
             for(int value = 1; value <= 13; ++value) {
@@ -56,6 +56,7 @@ void shoe::setup_round(std::string &err) {
     this->shuffle();
 }
 
+// draw a card from shoe to given hand
 card* shoe::draw_card(hand* h, std::string& err)  {
     if (!_cards.empty()) {
         card* drawn_card = _cards.back();
-- 
GitLab