Hit or Stand for 21 game

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 779 Views - Last Post: 25 October 2018 - 10:27 AM Rate Topic: ***-- 2 Votes

#1 Kenstar1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-October 18

Hit or Stand for 21 game

Posted 21 October 2018 - 09:06 PM

Good evening everyone I am working on getting my hit or stand function to work on my program. It seems like I am not able to get get the computer to register that I would like to hit or stand correctly. An understanding of what I am doing wrong would be great as well as any other tips you may have to offer.

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int* createDeck(); // Makes the deck for player and dealer
void printDeck(int*);// Print out the deck
int* shuffle(int* );// Shuffle the deck
int* deal(int*); // Makes the user and dealer gain cards that will not overlap
int* nxtdeals(int*);// Allows for the hit or stand after first deal is dealt.

int main()
{
  cout << "Shuffle: [n | u <seed>]:";
  char c; // choice for user.
  int  seed;// number users picks for see.


  int* rd = createDeck(); // rd = real deck
 
  cin >> c;
   if ( c == 'u')
  {   
    cin >> seed; // gain seed value from user
    srand(seed);
    int* sd = shuffle(rd); // calls shuffle function
    // printDeck(sd);
    deal(sd);
    printDeck(sd);
    nxtdeals(sd);
    printDeck(sd);    

  }
   else if ( c != 'u')// If user does not want to shuffle.
  {
      deal(rd); 
      printDeck(rd);
      nxtdeals(rd);         
  }       
}
    
int* createDeck()
{
  int* fulldeck = new int[52];
  int fv = 14, sv = 4; // Fv = face value and sv= Suite value
  int cv, cc = 0; // cc stands for card count and cv is the cardvalue
  
  for ( int i = 1; i <= sv; i++)
  {
    for ( int j = 2; j <= fv; j++)
    {
      cv = j + 100 * i;
      fulldeck[cc] = cv;
      cc++;
    }
  }
  return fulldeck;
}

int* shuffle(int* sdeck)
{
  int rv; // random value
  int temp; // temp to hold card value

  for ( int i = 0; i < 52; i++)
  {
    rv = rand() % 52;

    temp = sdeck[i];
    sdeck[i] = sdeck[rv];
    sdeck[rv] = temp;
  }
  return sdeck;
}


void printDeck(int* fulldeck)
{

  string clubs = "\u2663";
  string diamonds = "\u2666";
  string hearts = "\u2665";
  string spades = "\u2660";

  cout << "Player Dealer";

  for ( int i = 0; i < 4; i++)
  {
    // Value for how facevalue and suitevalue are calculated
     int facevalue = fulldeck[i] % 100;
     int suitvalue = fulldeck[i] / 100;

     string num;// string to hold facevalue actual numbers

    if ( facevalue == 2)
    {
      num = " 2";
    }
    else if ( facevalue == 3)
    {
      num = " 3";
    }
    else if ( facevalue == 4)
    {
      num =" 4";
    }
    else if ( facevalue == 5)
    {
      num = " 5";
    }
    else if ( facevalue == 6)
    {
      num = " 6";
    }
    else if ( facevalue == 7)
    {
      num = " 7";
    }
    else if ( facevalue == 8)
    {
      num = " 8";
    }
    else if ( facevalue == 9)
    {
      num = " 9";
    }
    else if ( facevalue == 10)
    {
      num = "10";
    }
    else if ( facevalue == 11)
    {
      num = " J";
    }
    else if ( facevalue == 12)
    {
      num = " Q";
    }
    else if ( facevalue == 13)
    {
      num = " K";
    }
    else if ( facevalue == 14)
    {
      num = " A";
    }
    
    if (!(i % 2) )
    {
      cout << endl;
    }
    cout << " |";

    // Used to get the value and display proper suite.
    if  (suitvalue == 1)
    {
      cout  << num << clubs << "";
    }
    else if ( suitvalue == 2)
    {
      cout <<" |" << num << diamonds << " | ";
    }
    else if ( suitvalue == 3)
    {
      cout << " |" << num << hearts << " | ";
    }
    else if ( suitvalue == 4)
    {
      cout << " |" << num << spades <<" | ";
    }
    if ( i % 2)
    {
      cout << " |";
    }
  }
}
    
int* deal(int* fulldeck)
{
  int dc = 0; // deck count 
  int pc = 0; // player count
  int dd = 0; // dealer count

  for ( int i = 0; i < 5; i++)
  {
    // Hands for players and deck for dealers
    int* phand = new int [52];
    int* dhand = new int [52];
    int* deck = fulldeck;// deck for dealer and players to draw from.

    phand[i] = 0;
    dhand[i] = 0;

    phand[pc] = deck[dc];
    dc++;
    pc++;

    dhand[dd] = deck[dc];
    dc++;
    dd++;
  }
}


 int* nxtdeals(int* fulldeck)
{
  
  int dc = 0; // deck count 
  int pc = 0; // player count
  int dd = 0; // dealer count

  int* phand = new int [52];
  int* dhand = new int [52];
  int* deck = fulldeck;// deck for dealer and players to draw from.
  // phand[i] = 0;
  // dhand[i] = 0;

  char p,d;
  for ( int i = 1; i < 4; i++)
  {
    // Hands for players and deck for dealers

     cout << "\n Round "<< i << " Player's turn\n ";
     cout << "hit or stand? [h/s]";
     cin >> p;
     cout << endl;
    
     if( p == 'h')
     {
      phand[pc] = deck[dc];
      dc++;
      pc++;
     }
     cout <<"Player hands " <<phand[dd] << " Deck count " << deck[dc]; 

     printDeck(fulldeck);
     
     cout << " Round "<< i << " Dealer's turn\n ";
     cout << "hit or stand? [h/s]";
     cin >> d;
     cout << endl;

     
     if ( d == 'h')
     {
      dhand[dd] = deck[dc];
      dc++;
      dd++;
     }
     cout <<"Dealer hands " <<dhand[dd] << " Deck count " << deck[dc]; 
     printDeck(fulldeck);
  }
}





Is This A Good Question/Topic? 0
  • +

Replies To: Hit or Stand for 21 game

#2 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: Hit or Stand for 21 game

Posted 21 October 2018 - 09:59 PM

int* deal(int* fulldeck)


this function is not void but doesn't return anything.

same goes for
int* nxtdeals(int* fulldeck)



I would suggest making them void()

As for hitting or standing what is it doing... what should it be doing ?
Was This Post Helpful? 1
  • +
  • -

#3 Kenstar1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-October 18

Re: Hit or Stand for 21 game

Posted 22 October 2018 - 03:20 AM

Thanks for the info so far. The hitting or standing should be allowing the player to gain an additional card if they wish. If they chose to stand then it should give that card value to the dealer if they decide to hit.

This post has been edited by andrewsw: 22 October 2018 - 03:45 AM
Reason for edit:: removed previous quote, just use the Reply button

Was This Post Helpful? 0
  • +
  • -

#4 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7328
  • View blog
  • Posts: 15,239
  • Joined: 16-October 07

Re: Hit or Stand for 21 game

Posted 22 October 2018 - 04:41 AM

It's actually unclear why you'd use new at all this program. You know what your arrays look like. This looks more like C than C++. Which it to say, too many pointers and too few classes working for you.

Quick questions about your current sigs:
int* createDeck(); // why do you need to create?  Worse, why is your deck a raw array?
void printDeck(int*);// fine, maybe
int* shuffle(int*); // what are you returning?
int* deal(int*); // what are you returning? Further, were is the deal going?
int* nxtdeals(int*); // what are you returning? How does this relate to deal?



How I'd start with your current C bend:
[code]
const int DECK_SIZE = 52; // no magic numbers
void initDeck(int *);
void printCards(int *cards, int size);
void shuffle(int *cards, int size);

// your initial deal
int deal(Deck, int &deckSize, int *hand, int &handSize, int *hand2, int &handSize2);
// however, this would also be nice for you
int dealCard(Deck, int &deckSize);
void playHand(Deck, int &deckSize);

// other helper functions
int faceValue(int);
int suitValue(int);
void printCard(int);



You'll notice the need to track the sizes in your stacks of cards. Yes, it's tiresome. Happily, you can use the language to help with that:
// without leaving C land, much...
// a struct would still be nice
// also, to show when a card is a card
typedef int Card;
struct Cards {
    Card items[DECK_SIZE];
    int size;
};

void initDeck(Cards &);
void printCards(const Cards &);
void shuffle(Cards &);

void dealCard(Cards &deck, Cards &player);
void playHand(Cards &);



And, if that makes sense, then:
// with a little more C++ joy
struct Cards {
    Card items[DECK_SIZE];
    int size;
    Cards(bool initDeck = false);
    void add(Card);
    bool deal(Cards &);
    void print() const;
    void shuffle();
};



Hope this helps.
Was This Post Helpful? 3
  • +
  • -

#5 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: Hit or Stand for 21 game

Posted 22 October 2018 - 02:13 PM

Yeah, having looked closer at your code,

you are clearly flogging a dead horse with your design baavgai has given you the outlines of one possible design with structs and reusable functions, reusable functions are great...

However, I am going to give you another possible design with of course reusable functions but using std::vector instead of structs.

#include <iostream>
#include <io.h>
#include <fcntl.h>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>

#define DECK_SIZE 52
#define SUIT_SIZE 13
#define NUMBER_SUITS 4
#define WINNING_TARGET 21

void display_initial_board(vector<wstring>Deck, vector<int>Cards, int &card_counter, vector<int>&Player, vector<int>&Computer)
{
    wcout << "Player     Computer" << endl;
    for(int i =0; i<4; i=i+2)
    {
        wcout << Deck[Cards[i]] << "         " << Deck[Cards[i+1]];
        Player.push_back(Cards[i]);
        Computer.push_back(Cards[i+1]);
        if(!i%2)
            wcout << endl;
    }
    card_counter=4;
}

int main()
{
    srand (unsigned (time(0)));
    _setmode(_fileno(stdout), _O_U16TEXT);

    wstring suit[NUMBER_SUITS] = {L"♣", L"♥", L"♠", L"♦"};
    wstring facevalue[SUIT_SIZE] = {L" 2",L" 3",L" 4",L" 5",L" 6",L" 7",L" 8",L" 9",L"10",L" J",L" Q",L" K",L" A"};
    int value_of_cards[SUIT_SIZE] = {2,3,4,5,6,7,8,9,10,10,10,10,1};
    vector<wstring> deck;
    vector<int> cards;
    vector<int> player_hand;
    vector<int> computer_hand;

    int step_through_cards =0;
    
    for(int i = 0; i<DECK_SIZE; i++)
    {

        deck.push_back(facevalue[i%SUIT_SIZE]+suit[i/SUIT_SIZE]);
        cards.push_back(i);

    }
    random_shuffle(cards.begin(), cards.end());



    wcout << L" J♠ BlackJack J♣" << endl << L"|A Game of Cards|" << endl << endl;


    display_initial_board(deck, cards, step_through_cards, player_hand, computer_hand);

    int Total =0;
    int computer_Total =0;
    bool computer_not_won =true;

    return 0;

}



functions to think about developing

void display_a_new_card
bool check_if_bust
bool check_for_a_win
void player_turn
void computer_turn



Also try to give your variables meaningful names be descriptive and remember both baavgai and my design are only one of many possible designs.
Was This Post Helpful? 2
  • +
  • -

#6 Kenstar1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-October 18

Re: Hit or Stand for 21 game

Posted 22 October 2018 - 05:39 PM

Thank-you both for the replies. This has helped me tremendously, yet the only problem is that my class has not learned about Vectors, Class or Structs. Also, we are not allowed to use pass-by-reference only by value.
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 01:20 AM

Right ok,

We never knew this was for a class,

We never knew you can't use Vectors or classes or structs..

It would help us... well me anyway..

if you could explain rather not what you can't use but what you can use... that would be helpful.
Was This Post Helpful? 1
  • +
  • -

#8 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7328
  • View blog
  • Posts: 15,239
  • Joined: 16-October 07

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 01:40 AM

View PostKenstar1, on 22 October 2018 - 07:39 PM, said:

we are not allowed to use pass-by-reference only by value.

To be clear, if you are passing pointers, you are still passing by reference, just only as a C programmer would, not a C++ programmer. Yes, a pointer is just a value; but what does that value represent?

So, understanding you're using the C++ language but basically can't use it's foundation features...

Pointers yes, structs no:
const int DECK_SIZE = 52;
void initDeck(int *);
void printCard(int);
void printCards(int *cards, int size);

void dealCard(int *deck, int *deckSize, int *hand, int *handsize);



That dealCard is a very C sig, but that's what we're stuck with. Arrays and simple pointers to size become ambiguous because, C.

You can organize C code without structs, but your functions must define the meaning your types might have and ensure consistency.

If you're allowed to use typedef, you can mitigate confusion a little:
const int DECK_SIZE = 52;

typedef int Cards[DECK_SIZE];
void initDeck(Cards);
void printCard(int);
void printCards(Cards, int size);

void dealCard(Cards, int *deckSize, Cards, int *handsize);



Actually, if you really wanted to go down the C hole of doom, you could make one of those array positions size...

Be aware you are not being taught C++ correctly. But you, as a student, have a job to appease your instructor, no matter how wrong headed they are. C is also a fun language and it looks like you're learning that. Keep that in mind. Good luck.
Was This Post Helpful? 1
  • +
  • -

#9 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6565
  • View blog
  • Posts: 22,530
  • Joined: 05-May 12

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 03:41 AM

... that or your teacher is of the generation that learned C++ as "C with classes" and so is also teaching it the same way.
Was This Post Helpful? 1
  • +
  • -

#10 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7328
  • View blog
  • Posts: 15,239
  • Joined: 16-October 07

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 05:26 AM

@Skydiver: I would have noted that, except that they are explicitly not allowed to use classes. At which point it's basically C++ with wonkier output operators and doubly confusing & symbols.
Was This Post Helpful? 1
  • +
  • -

#11 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6565
  • View blog
  • Posts: 22,530
  • Joined: 05-May 12

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 06:18 AM

Considering that structs are also verboten, perhaps the this is a case of C++ being taught as "FORTRAN-77 in C++". It's been years, but what I recall is that arrays is what is used to simulate struct's in FORTRAN.
Was This Post Helpful? 0
  • +
  • -

#12 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 07:01 AM

I agree,

was just thinking that this is not how I would teach C++ but rather it all just looks so C like, but you can't even use a struct so worse than C, but let us assume C and try to do it that way.

Was also thinking to myself who on earth gives Blackjack as an assignment without covering structs or std::vector or std::array even, sadomasochists that's who !!

Anyway, grump over.

C design of a general Blackjack idea.. might suit you better if you pardon the pun.

#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <time.h>
#include <wchar.h>

#define SUIT_SIZE 13
#define NUMBER_SUITS 4
#define WINNING_TARGET 21
#define DECK_SIZE 52
#define MAX_HAND  10
#define LENGTH_SYMBOL 2
#define LENGTH_NUMBER 3


int display_initial_board(int card_counter, wchar_t Deck[DECK_SIZE][NUMBER_SUITS], int Cards[DECK_SIZE], int Player[MAX_HAND], int Computer[MAX_HAND])
{


    int Player_counter = 0;
    int Computer_counter = 0;
    wprintf(L"Player     Computer \n");
    for(int i =0; i<4; i=i+2)
    {
        if(i<2)
        {
            wprintf(L"%s          %s\n", Deck[Cards[i]],Deck[Cards[i+1]]);

            Player[Player_counter] = Cards[i];
            Player_counter++;
            Computer[Computer_counter] = Cards[i+1];
            Computer_counter++;
        }

        if(i==2)
        {

            Player[Player_counter] = Cards[i];
            Player_counter++;
            Computer[Computer_counter] = Cards[i+1];
            Computer_counter++;
            wprintf(L"%s          %s\n", Deck[Cards[i]],Deck[Cards[i+1]]);

        }

    }
    card_counter= 4;

    return card_counter;
}

void shuffle_cards(int Cards[DECK_SIZE])
{
    /* shuffle cards randomly */

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

        int swap_first = rand()  %52;
        int swap_second = rand() %52;
        int temp = Cards[swap_first];
        int temp2 = Cards[swap_second];
        Cards[swap_first]  = temp2;
        Cards[swap_second] = temp;
    }

}

void new_deck(wchar_t Deck[DECK_SIZE][NUMBER_SUITS], int Cards[DECK_SIZE],wchar_t Suit[NUMBER_SUITS][LENGTH_SYMBOL],wchar_t Facevalue[SUIT_SIZE][LENGTH_NUMBER])
{
    /* Initialise deck*/
    for(int i = 0; i<DECK_SIZE; i++)
    {
        wchar_t buffer[NUMBER_SUITS];
        swprintf(buffer, NUMBER_SUITS, L"%s%s", Facevalue[i%SUIT_SIZE], Suit[i/SUIT_SIZE]);
        wcscat(Deck[i], buffer);
        Cards[i]= i;

    }
}
int main()
{
    srand ((time(0)));
    _setmode(_fileno(stdout), _O_U16TEXT);

    wchar_t suit[NUMBER_SUITS][LENGTH_SYMBOL] = { {L"♣"},{L"♥"},{L"♠"},{L"♦"} };



    wchar_t facevalue[SUIT_SIZE][LENGTH_NUMBER] = { {L" 2"},{L" 3"},{L" 4"},{L" 5"},{L" 6"},{L" 7"},{L" 8"},{L" 9"},{L"10"},{L" J"},{L" Q"},{L" K"},{L" A"} };
    int value_of_cards[SUIT_SIZE] = {2,3,4,5,6,7,8,9,10,10,10,10,1};

    wprintf(L" J♠ BlackJack J♣\n");
    wprintf(L"|A Game of Cards|\n");


    wchar_t deck[DECK_SIZE][NUMBER_SUITS]= {{0}};
    int cards[DECK_SIZE];
    int player_hand[MAX_HAND];
    int player_hand_value=0;
    int computer_hand[MAX_HAND];
    int computer_hand_value=0;
    int step_through_cards = 0;
    int player_card_counter = 0;
    int computer_card_counter = 0;

    new_deck(deck,cards,suit,facevalue);
    /*shuffle*/
    shuffle_cards(cards);
    /*Initial Board*/
    step_through_cards = display_initial_board(step_through_cards,deck,cards,player_hand,computer_hand);

    player_card_counter = player_card_counter+2;
    computer_card_counter = computer_card_counter+2;

    /*Show how to calculate actual numerical card Totals, Aces can be one or eleven*/

    for(int i =0; i< player_card_counter; i++)
    {
       player_hand_value = player_hand_value + value_of_cards[player_hand[i]%SUIT_SIZE];
       if(value_of_cards[player_hand[i]%SUIT_SIZE]==1)/*check for Ace*/
        player_hand_value = player_hand_value+10;
    }
    wprintf(L"\nPlayer cards Total value is %d\n",player_hand_value);


    for(int i =0; i< computer_card_counter; i++)
    {
        computer_hand_value = computer_hand_value + value_of_cards[computer_hand[i]%SUIT_SIZE];
        if(value_of_cards[computer_hand[i]%SUIT_SIZE]==1)/*check for Ace*/
        computer_hand_value = computer_hand_value+10;
    }

    wprintf(L"Computer cards Total value is %d\n",computer_hand_value);
    return 0;
}



Was This Post Helpful? 1
  • +
  • -

#13 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7328
  • View blog
  • Posts: 15,239
  • Joined: 16-October 07

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 11:01 AM

Ok, I'll admit, the idea of stuffing the size in the array got the better of me.

So, quick zero struck blackjack start:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define DECK_SIZE 52
#define FACES 13
#define SUITS 4
#define CARDS_SIZE 53
#define SIZE_INDEX DECK_SIZE
#define PLAYERS_COUNT 4

typedef unsigned char Card;
typedef Card Cards[CARDS_SIZE];
typedef Cards Players[PLAYERS_COUNT];

void initCards(Cards);
void initDeck(Cards);
int cardsSize(Cards);
bool popCard(Cards, Card *);
bool pushCard(Cards, Card);
void showCard(Card);
void showCards(Cards);
int cardFace(Card);
int cardSuit(Card);
void shuffleCards(Cards);

void initBlackjackGame(Cards deck, Players);
void display(Players);
int handValue(Cards);

int main() {
    srand((time(0)));

    Cards deck;
    Players players;
    initBlackjackGame(deck, players);
    display(players);
    return 0;
}

void display(Players xs) {
    for (int i = 0; i < PLAYERS_COUNT; i++) {
        Cards *player = xs + i;
        printf("Player %d: (%d)", (i + 1), handValue(player));
        showCards(player);
    }
}

void initBlackjackGame(Cards deck, Players players) {
    initDeck(deck);
    shuffleCards(deck);
    for (int i = 0; i < PLAYERS_COUNT; i++) {
        initCards(players + i);
    }
    for (int j = 0; j < 2; j++) {
        for (int i = 0; i < PLAYERS_COUNT; i++) {
            Card card;
            popCard(deck, &card);
            pushCard(players + i, card);
        }
    }
}

int handValue(Cards cards) {
    int aceCount = 0;
    int value = 0;
    for (int i = 0, size = cardsSize(cards); i < size; i++) {
        int face = cardFace(cards[i]) + 1;
        if (face == 1) {
            aceCount += 1;
            value += 11;
        } else {
            value += (face >= 10) ? 10 : face;
        }
    }
    while (value > 21 && aceCount > 0) { value -= 11; aceCount--; }
    return value;
}

void initCards(Cards cards) { cards[SIZE_INDEX] = 0; }

void initDeck(Cards cards) {
    initCards(cards);
    for (int i = 0; i < DECK_SIZE; i++) { pushCard(cards, i); }
}

int cardsSize(Cards cards) { return cards[SIZE_INDEX]; }


bool pushCard(Cards cards, Card c) {
    if (cards[SIZE_INDEX] < CARDS_SIZE) {
        cards[cards[SIZE_INDEX]++] = c;
        return true;
    }
    return false;
}

bool popCard(Cards cards, Card *c) {
    if (cards[SIZE_INDEX] < CARDS_SIZE) {
        *c = cards[--cards[SIZE_INDEX]];
        return true;
    }
    return false;
}

int cardFace(Card c) { return c % FACES; }

int cardSuit(Card c) { return c / FACES; }

void showCard(Card c) {
    static char *suits = "SDCH";
    static char *faces = "A23456789TJQK";
    printf("%c%c", faces[cardFace(c)], suits[cardSuit(c)]);
}

void showCards(Cards cards) {
    for (int i = 0, size = cardsSize(cards); i < size; i++) {
        showCard(cards[i]);
        printf(" ");
    }
    printf("\n");
}

void shuffleCards(Cards cards) {
    for (int i = cardsSize(cards) - 1; i != 0; i--) {
        int idx = rand() % i;
        Card t = cards[i];
        cards[i] = cards[idx];
        cards[idx] = t;
    }
}


Was This Post Helpful? 1
  • +
  • -

#14 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1554
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 11:56 AM

You do realize that,

I was only joking :)/>

You know.... your C++ is so bad it looks like C......

Or your C++ lecturer is so bad it looks like he is teaching you C...


Are we allowed typedefs have they been covered by the Lecturer?

Also, your graphics "SDCH", WHAT, YOU CANNOT BE SERIOUS!!

Its "♠♦♣♥" or I'm going home ;P

This post has been edited by snoopy11: 23 October 2018 - 11:58 AM

Was This Post Helpful? 1
  • +
  • -

#15 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6565
  • View blog
  • Posts: 22,530
  • Joined: 05-May 12

Re: Hit or Stand for 21 game

Posted 23 October 2018 - 04:48 PM

I have a feeling that our OP's teacher is not opposed to the use of globals, or may even encourage it. If I can use globals, then the lack of structs is not as painful because I can access information like the current deck size and index into the deck for what card will be dealt next. Passing around player hand information will still be a bit painful but not insurmountable -- think old style BASIC GOSUB calls where subroutine parameters are passed through globals.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2