Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
28 kB
13
Indexable
Never
#ifndef BLACKJACK_H
#define BLACKJACK_H
#include "ucm_random"
#include <iostream>

// C++ macros for changing background color and text color of the terminal
#define RESET "\033[0m"             // reset terminal
#define WHITE_BG "\033[47m"         // white background
#define RED_CARD "\033[1;47;31m"    // white background + red text color
#define BLACK_CARD "\033[1;47;30m"  // white background + black text color


// shuffle cards
void shuffleCards(std::string cards[], int size){

    RNG cardA, cardB;
    std::string temp;
    int card_A;
    int card_B;

    for (int i = 0; i < 800; i++) {
        card_A = cardA.get(0,size-1);
        card_B = cardB.get(0,size-1);

        temp = cards[card_A];
        cards[card_A] = cards[card_B];
        cards[card_B] = temp;
    }

}










// Print Card functions

void printTop(std::string hand[], int numberOfCards){
    for (int i = 0; i < numberOfCards; i++){
        std::cout << WHITE_BG << "          " << RESET;
        if (i < numberOfCards - 1) {
           std::cout << " ";
        }
    }
    std::cout << std::endl;
}

void printTopNumberSlot(std::string hand[], int numberOfCards){
    for (int i = 0; i < numberOfCards; i++){
            
           
        if (hand[i] == "AH" || hand[i] == "AD"){
            std::cout << RED_CARD << "  A       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "2H" || hand[i] == "2D"){
            std::cout << RED_CARD << "  2       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "3H" || hand[i] == "3D"){
            std::cout << RED_CARD << "  3       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "4H" || hand[i] == "4D"){
            std::cout << RED_CARD << "  4       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "5H" || hand[i] == "5D"){
            std::cout << RED_CARD << "  5       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "6H" || hand[i] == "6D"){
            std::cout << RED_CARD << "  6       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "7H" || hand[i] == "7D"){
            std::cout << RED_CARD << "  7       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "8H" || hand[i] == "8D"){
            std::cout << RED_CARD << "  8       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "9H" || hand[i] == "9D"){
            std::cout << RED_CARD << "  9       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "10H" || hand[i] == "10D"){
            std::cout << RED_CARD << "  10      " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "JH" || hand[i] == "JD"){
            std::cout << RED_CARD << "  J       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "QH" || hand[i] == "QD"){
            std::cout << RED_CARD << "  Q       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "KH" || hand[i] == "KD"){
            std::cout << RED_CARD << "  K       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AC" || hand[i] == "AS"){
            std::cout << BLACK_CARD << "  A       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "2C" || hand[i] == "2S"){
            std::cout << BLACK_CARD << "  2       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "3C" || hand[i] == "3S"){
            std::cout << BLACK_CARD << "  3       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "4C" || hand[i] == "4S"){
            std::cout << BLACK_CARD << "  4       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "5C" || hand[i] == "5S"){
            std::cout << BLACK_CARD << "  5       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "6C" || hand[i] == "6S"){
            std::cout << BLACK_CARD << "  6       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "7C" || hand[i] == "7S"){
            std::cout << BLACK_CARD << "  7       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "8C" || hand[i] == "8S"){
            std::cout << BLACK_CARD << "  8       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "9C" || hand[i] == "9S"){
            std::cout << BLACK_CARD << "  9       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "10C" || hand[i] == "10S"){
            std::cout << BLACK_CARD << "  10      " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "JC" || hand[i] == "JS"){
            std::cout << BLACK_CARD << "  J       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "QC" || hand[i] == "QS"){
            std::cout << BLACK_CARD << "  Q       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "KC" || hand[i] == "KS"){
            std::cout << BLACK_CARD << "  K       " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        }
        
    }
    std::cout << std::endl;
}

void printTopOfSuit(std::string hand[], int numberOfCards){
    for (int i = 0; i < numberOfCards; i++){

        if (hand[i] == "AH" || hand[i] == "2H" || hand[i] == "3H" || hand[i] == "4H" || hand[i] == "5H" || hand[i] == "6H" || hand[i] == "7H" || hand[i] == "8H" || hand[i] == "9H" || hand[i] == "10H" || hand[i] == "JH" || hand[i] == "KH" || hand[i] == "QH"){
            std::cout << RED_CARD << "   _  _   " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AD" || hand[i] == "2D" || hand[i] == "3D" || hand[i] == "4D" || hand[i] == "5D" || hand[i] == "6D" || hand[i] == "7D" || hand[i] == "8D" || hand[i] == "9D" || hand[i] == "10D" || hand[i] == "JD" || hand[i] == "KD" || hand[i] == "QD"){
            std::cout << RED_CARD << "    /\\    " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AC" || hand[i] == "2C" || hand[i] == "3C" || hand[i] == "4C" || hand[i] == "5C" || hand[i] == "6C" || hand[i] == "7C" || hand[i] == "8C" || hand[i] == "9C" || hand[i] == "10C" || hand[i] == "JC" || hand[i] == "KC" || hand[i] == "QC"){
            std::cout << BLACK_CARD << "    __    " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AS" || hand[i] == "2S" || hand[i] == "3S" || hand[i] == "4S" || hand[i] == "5S" || hand[i] == "6S" || hand[i] == "7S" || hand[i] == "8S" || hand[i] == "9S" || hand[i] == "10S" || hand[i] == "JS" || hand[i] == "KS" || hand[i] == "QS"){
            std::cout << BLACK_CARD << "    /\\    " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } 

        
    }
    std::cout << std::endl;
}

void printMiddleOfSuit1(std::string hand[], int numberOfCards){
    for (int i = 0; i < numberOfCards; i++){

        if (hand[i] == "AH" || hand[i] == "2H" || hand[i] == "3H" || hand[i] == "4H" || hand[i] == "5H" || hand[i] == "6H" || hand[i] == "7H" || hand[i] == "8H" || hand[i] == "9H" || hand[i] == "10H" || hand[i] == "JH" || hand[i] == "KH" || hand[i] == "QH"){
            std::cout << RED_CARD << "  ( \\/ )  " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AD" || hand[i] == "2D" || hand[i] == "3D" || hand[i] == "4D" || hand[i] == "5D" || hand[i] == "6D" || hand[i] == "7D" || hand[i] == "8D" || hand[i] == "9D" || hand[i] == "10D" || hand[i] == "JD" || hand[i] == "KD" || hand[i] == "QD"){
            std::cout << RED_CARD << "   /  \\   " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AC" || hand[i] == "2C" || hand[i] == "3C" || hand[i] == "4C" || hand[i] == "5C" || hand[i] == "6C" || hand[i] == "7C" || hand[i] == "8C" || hand[i] == "9C" || hand[i] == "10C" || hand[i] == "JC" || hand[i] == "KC" || hand[i] == "QC"){
            std::cout << BLACK_CARD << "   (  )   " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AS" || hand[i] == "2S" || hand[i] == "3S" || hand[i] == "4S" || hand[i] == "5S" || hand[i] == "6S" || hand[i] == "7S" || hand[i] == "8S" || hand[i] == "9S" || hand[i] == "10S" || hand[i] == "JS" || hand[i] == "KS" || hand[i] == "QS"){
            std::cout << BLACK_CARD << "   /  \\   " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } 

        
    }
    std::cout << std::endl;
}

void printMiddleOfSuit2(std::string hand[], int numberOfCards){
    for (int i = 0; i < numberOfCards; i++){

        if (hand[i] == "AH" || hand[i] == "2H" || hand[i] == "3H" || hand[i] == "4H" || hand[i] == "5H" || hand[i] == "6H" || hand[i] == "7H" || hand[i] == "8H" || hand[i] == "9H" || hand[i] == "10H" || hand[i] == "JH" || hand[i] == "KH" || hand[i] == "QH"){
            std::cout << RED_CARD << "   \\  /   " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AD" || hand[i] == "2D" || hand[i] == "3D" || hand[i] == "4D" || hand[i] == "5D" || hand[i] == "6D" || hand[i] == "7D" || hand[i] == "8D" || hand[i] == "9D" || hand[i] == "10D" || hand[i] == "JD" || hand[i] == "KD" || hand[i] == "QD"){
            std::cout << RED_CARD << "   \\  /   " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AC" || hand[i] == "2C" || hand[i] == "3C" || hand[i] == "4C" || hand[i] == "5C" || hand[i] == "6C" || hand[i] == "7C" || hand[i] == "8C" || hand[i] == "9C" || hand[i] == "10C" || hand[i] == "JC" || hand[i] == "KC" || hand[i] == "QC"){
            std::cout << BLACK_CARD << "  (____)  " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } else if (hand[i] == "AS" || hand[i] == "2S" || hand[i] == "3S" || hand[i] == "4S" || hand[i] == "5S" || hand[i] == "6S" || hand[i] == "7S" || hand[i] == "8S" || hand[i] == "9S" || hand[i] == "10S" || hand[i] == "JS" || hand[i] == "KS" || hand[i] == "QS"){
            std::cout << BLACK_CARD << "  (____)  " << RESET;
            if (i < numberOfCards - 1) {
                std::cout << " ";
            }
        } 

        
    }
    std::cout << std::endl;
}

void bottom(std::string hand[], int amountOfCards){
    for(int i = 0; i < amountOfCards; i++){
        if (hand[i]== "AC" || hand[i] == "AS"){
        std::cout << BLACK_CARD << "       A  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "2C" || hand[i] == "2S"){
        std::cout << BLACK_CARD << "       2  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "3C" || hand[i] == "3S"){
            std::cout << BLACK_CARD << "       3  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "4C" || hand[i] == "4S"){
            std::cout << BLACK_CARD << "       4  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "5C" || hand[i] == "5S"){
            std::cout << BLACK_CARD << "       5  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "6C" || hand[i] == "6S"){
            std::cout << BLACK_CARD << "       6  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "7C" || hand[i] == "7S"){
            std::cout << BLACK_CARD << "       7  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "8C" || hand[i] == "8S"){
            std::cout << BLACK_CARD << "       8  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "9C" || hand[i] == "9S"){
            std::cout << BLACK_CARD << "       9  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "10C" || hand[i] == "10S"){
            std::cout << BLACK_CARD << "      10  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "JC" || hand[i] == "JS"){
            std::cout << BLACK_CARD << "       J  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "QC" || hand[i] == "QS"){
            std::cout << BLACK_CARD << "       Q  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "KC" || hand[i] == "KS"){
            std::cout << BLACK_CARD << "       K  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if (hand[i]== "AH" || hand[i] == "AD"){
        std::cout << RED_CARD << "       A  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "2H" || hand[i] == "2D"){
            std::cout << RED_CARD << "       2  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "3H" || hand[i] == "3D"){
            std::cout << RED_CARD << "       3  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "4H" || hand[i] == "4D"){
            std::cout << RED_CARD << "       4  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "5H" || hand[i] == "5D"){
            std::cout << RED_CARD << "       5  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "6H" || hand[i] == "6D"){
            std::cout << RED_CARD << "       6  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "7H" || hand[i] == "7D"){
            std::cout << RED_CARD << "       7  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "8H" || hand[i] == "8D"){
        std::cout << RED_CARD << "       8  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "9H" || hand[i] == "9D"){
            std::cout << RED_CARD << "       9  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "10H" || hand[i] == "10D"){
            std::cout << RED_CARD << "      10  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "JH" || hand[i] == "JD"){
            std::cout << RED_CARD << "       J  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "QH" || hand[i] == "QD"){
            std::cout << RED_CARD << "       Q  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "KH" || hand[i] == "KD"){
            std::cout << RED_CARD << "       K  " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }
    }
    std::cout << std::endl;
}   

void bottom2(std::string hand[], int amountOfCards){
    for(int i = 0; i < amountOfCards; i++){
        if (hand[i]== "AC" || hand[i] == "AS"){
        std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "2C" || hand[i] == "2S"){
        std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "3C" || hand[i] == "3S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "4C" || hand[i] == "4S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "5C" || hand[i] == "5S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "6C" || hand[i] == "6S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "7C" || hand[i] == "7S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "8C" || hand[i] == "8S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "9C" || hand[i] == "9S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "10C" || hand[i] == "10S"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "JC" || hand[i] == "JS"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "QC" || hand[i] == "QS"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "KC" || hand[i] == "KS"){
            std::cout << BLACK_CARD << "    ||    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if (hand[i]== "AH" || hand[i] == "AD"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "2H" || hand[i] == "2D"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "3H" || hand[i] == "3D"){
            std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "4H" || hand[i] == "4D"){
            std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
                std::cout << " ";
            }
        }else if(hand[i]== "5H" || hand[i] == "5D"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "6H" || hand[i] == "6D"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "7H" || hand[i] == "7D"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "8H" || hand[i] == "8D"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "9H" || hand[i] == "9D"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "10H" || hand[i] == "10D"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "JH" || hand[i] == "JD"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "QH" || hand[i] == "QD"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }
        }else if(hand[i]== "KH" || hand[i] == "KD"){
        std::cout << RED_CARD << "    \\/    " << RESET;
            if (i < amountOfCards - 1){
            std::cout << " ";
            }

        }       
        
    }
    std::cout << std::endl;
} 

void printBottom(std::string hand[], int amountOfCards){
    for (int i = 0; i < amountOfCards; i++){
        std::cout << WHITE_BG << "          " << RESET;

        if (i < amountOfCards - 1){
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}

void printHand(std::string hand[], int size){
    printTop(hand, size);
    printTopNumberSlot(hand, size);
    printTopOfSuit(hand, size);
    printMiddleOfSuit1(hand, size);
    printMiddleOfSuit2(hand, size);
    bottom2(hand, size);
    bottom(hand, size);
    printBottom(hand, size);
}










int calculatePoints(std::string hand[], int size){
    int score = 0;

    for (int i = 0; i < size; i++){

        if (hand[i] == "AH" || hand[i] == "AS" || hand[i] == "AC" || hand[i] == "AD"){
            score += 11;
        } else if (hand[i] == "2H" || hand[i] == "2S" || hand[i] == "2C" || hand[i] == "2D"){
            score += 2;
        } else if (hand[i] == "3H" || hand[i] == "3S" || hand[i] == "3C" || hand[i] == "3D"){
            score += 3;
        } else if (hand[i] == "4H" || hand[i] == "4S" || hand[i] == "4C" || hand[i] == "4D"){
            score += 4;
        } else if (hand[i] == "5H" || hand[i] == "5S" || hand[i] == "5C" || hand[i] == "5D"){
            score += 5;
        } else if (hand[i] == "6H" || hand[i] == "6S" || hand[i] == "6C" || hand[i] == "6D"){
            score += 6;
        } else if (hand[i] == "7H" || hand[i] == "7S" || hand[i] == "7C" || hand[i] == "7D"){
            score += 7;
        } else if (hand[i] == "8H" || hand[i] == "8S" || hand[i] == "8C" || hand[i] == "8D"){
            score += 8;
        } else if (hand[i] == "9H" || hand[i] == "9S" || hand[i] == "9C" || hand[i] == "9D"){
            score += 9;
        } else if (hand[i] == "10H" || hand[i] == "10S" || hand[i] == "10C" || hand[i] == "10D"){
            score += 10;
        } else if (hand[i] == "JH" || hand[i] == "JS" || hand[i] == "JC" || hand[i] == "JD" || hand[i] == "QH" || hand[i] == "QS" || hand[i] == "QC" || hand[i] == "QD" || hand[i] == "KH" || hand[i] == "KS" || hand[i] == "KC" || hand[i] == "KD"){
            score += 10;
        }

    }
    for (int i = 0; i < size; i++){
        if (hand[i] == "AH" || hand[i] == "AD" || hand[i] == "AS" || hand[i] == "AC"){
            if (score > 21){
                score = score - 10;
            }
        }
    }

    return score;
}







// determine outcome
std::string determineOutcome(std::string playerHand[], int playerCardsCount, std::string dealerHand[], int dealerCardsCount){
    std::string outcome;

    int playerScore = calculatePoints(playerHand, playerCardsCount);
    for (int i = 0; i < playerCardsCount; i++){
        if (playerHand[i] == "AH" || playerHand[i] == "AD" || playerHand[i] == "AS" || playerHand[i] == "AC"){
            if (playerScore > 21){
                playerScore = playerScore - 10;
            }
        }
    }

    int dealerScore = calculatePoints(dealerHand, dealerCardsCount);
    for (int i = 0; i < dealerCardsCount; i++){
        if (dealerHand[i] == "AH" || dealerHand[i] == "AD" || dealerHand[i] == "AS" || dealerHand[i] == "AC"){
            if (dealerScore > 21){
                dealerScore = dealerScore - 10;
            }
        }
    }

    // Calculate outcomes
    if (playerScore == 21 && playerCardsCount > 2 && dealerScore != 21){
        outcome = "You win!";
    } else if (playerScore == 21 && playerCardsCount == 2 && dealerScore > 21){
        outcome = "You got a blackjack!";
    } else if (playerScore == 21 && playerCardsCount == 2 && dealerScore < 21){
        outcome = "You got a blackjack!";
    } 

    if (dealerScore == 21 && dealerCardsCount > 2 && playerScore != 21){
        outcome = "You lose!";
    } else if (dealerScore == 21 && dealerCardsCount == 2 && playerScore > 21){
        outcome = "Dealer got a blackjack!";
    } else if (dealerScore == 21 && dealerCardsCount == 2 && playerScore < 21){
        outcome = "Dealer got a blackjack!";
    }
    
    if (playerScore == 21 && playerCardsCount == 2 && dealerScore == 21){
        outcome = "You got a blackjack!";
    }

    if (playerScore == 21 && playerCardsCount == 2 && dealerScore == 21 && dealerCardsCount == 2){
        outcome = "It's a tie!";
    }

    if (playerScore < 21 && dealerScore < 21 && dealerScore < playerScore ){
        outcome = "You win!";
    }

    if (playerScore < 21 && dealerScore < 21 && dealerScore > playerScore ){
        outcome = "You lose!";
    }

    if (playerScore < 21 && dealerScore > 21){
        outcome = "You win!";
    } 

    if (dealerScore < 21 && playerScore > 21){
        outcome = "You lose!";
    } 

    if (dealerScore > 21 && playerScore > 21){
        outcome = "You lose!";
    }  

    if (dealerScore < 21 && playerScore < 21 && dealerScore == playerScore){
        outcome = "It's a tie!";
    }

    return outcome;
}


#endif
Leave a Comment