C++ How to check if a hand in 3 card poker is a straight? : AskProgramming


I am stuck on how to check if this hand contains a straight. The reason being is that the card number, is a string. I can’t compare value because there is 5 different 10’s.

Code below is just to show what a card and a deck is made of.

struct PlayingCard
{
    string cardNumber;
    string cardSuit;
    int cardValue;
};

vector<PlayingCard> createDeck(vector<PlayingCard> playingDeck)
{
    string cardFaces[13] = {"TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING", "ACE"};
    string cardSuits[4] = {"HEARTS", "DIAMONDS", "SPADES", "CLUBS"};
    int cardValues[13] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11};
    int suitCounter = 0;

    // Creates Deck
    for (int i=0; i < 52; i++)
    {
        playingDeck.push_back(PlayingCard());
        playingDeck[i].cardNumber = cardFaces[i % 13];
        playingDeck[i].cardSuit = cardSuits[suitCounter];
        playingDeck[i].cardValue = cardValues[i % 13];
        if ((i+1) % 13 == 0)
        {
            suitCounter = suitCounter + 1;
        }
    }
    return playingDeck;
}

vector<PlayingCard> shuffleDeck(vector<PlayingCard> playingDeck)
{
    srand(time(NULL));

    // Shuffles Deck
    for (int original = 0; original < 52; original++)
    {
        int r = rand() % 52;

        PlayingCard tempDeck[52];
        tempDeck[original] = playingDeck[original];
        playingDeck[original] = playingDeck[r];
        playingDeck[r] = tempDeck[original];
    }
    return playingDeck;
}

The code below is my 3 card poker function which is where the issue is.

int threeCardGame(int betAmount, int userBalance)
{

    int menuChoice;
    bool gameLoop;
    int anteBet;
    int playOrFold;
    int pairPlusBet;
    int sixCardBet;
    int handRank;
    cout << "Welcome to the Three Card Poker Game" << endl;
    cout << "Enter 1 to play" << endl;
    cout << "Enter 2 for pay table a rules" << endl;
    cin >> menuChoice;

    if(menuChoice == 1)
    {
        gameLoop = true;
    }
    if(menuChoice == 2)
    {

    }

    while (gameLoop)
    {
        vector<PlayingCard> playingDeck;
        playingDeck = createDeck(playingDeck);
        playingDeck = shuffleDeck(playingDeck);
        vector<PlayingCard> dealerHand;
        vector<PlayingCard> userHand;
        cardDraw(userHand, playingDeck);
        cardDraw(userHand, playingDeck);
        cardDraw(userHand, playingDeck);
        cardDraw(dealerHand, playingDeck);
        cardDraw(dealerHand, playingDeck);
        cardDraw(dealerHand, playingDeck);

        getValidBet(anteBet, userBalance);

        for (int i=0; i < userHand.size(); i++)
        {
            cout << userHand[i].cardNumber << " of " << userHand[i].cardSuit << " Value: " << userHand[i].cardValue << endl;
        }
        // Dealer Hand
        for (int i=0; i < userHand.size(); i++)
        {
            cout << "[HIDDEN]" << endl;
        }
        cout << "Enter 1 to play " << endl;
        cout << "Enter 2 to fold " << endl;
        cin >> playOrFold;
        if (playOrFold == 1)
        {
            if (userHand[0].cardNumber == userHand [1].cardNumber || userHand[0].cardNumber == userHand [2].cardNumber || userHand[1].cardNumber == userHand [2].cardNumber)
            {
                handRank = 1;
            }
            if (userHand[0].cardNumber == userHand [1].cardNumber && userHand[0].cardNumber == userHand [2].cardNumber)
            {
                handRank = 2;
            }
            if(userHand[])
        }
    }


}



Source link

GuciPoker
Copyright © 2020 GuciPoker | All rights reserved | All logos and trademarks belong to their respective companies