Blackjack game.. what next

I've done this so far but I'm struggling with the actual game concept, I don't know what to put in the Play() function or even know how to start it. Any help would be great

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

#include "pch.h"
#include <iostream>
#include <cstdlib> // for seed
#include <ctime> // for time

using namespace std;

#define NUMBER_OF_CARDS 52

enum SUIT {HEARTS, DIAMONDS, CLUBS, SPADES};

struct Card {
	SUIT suit; // H, D, S, C
	int value; // A, 2, 3, 4, 5, 6, 7, 8, 9, 10
	int score; // A = 1 2 = 2, Q = 10

};

Card Pack[NUMBER_OF_CARDS];
void SetupPack();
void SetupHearts();
void SetupDiamonds();
void SetupClubs();
void SetupSpades();

void Play(); //play blackjack


void ShufflePack(); //shuffle deck of cards to make random



int main()
{
	
}



void Play()
{

	ShufflePack();

	
		


}


void SetupPack()
{
	SetupHearts();
	SetupDiamonds();
	SetupClubs();
	SetupSpades();
}

void SetupHearts()
{
	for (int loop = 0; loop <= 12; loop++)
	{
		Pack[loop].suit = HEARTS;
		Pack[loop].value = loop + 1;
		Pack[loop].score = loop + 1;

	}
	//score for Jack, Queen, King
	Pack[10].score = 10;
	Pack[11].score = 10;
	Pack[12].score = 10;
}

void SetupDiamonds()
{
	for (int loop = 13; loop <= 25; loop++)
	{
		Pack[loop].suit = DIAMONDS;
		Pack[loop].value = loop + 1;
		Pack[loop].score = loop + 1;

	}
	//score for Jack, Queen, King
	Pack[23].score = 10;
	Pack[24].score = 10;
	Pack[25].score = 10;
}


void SetupClubs()
{
	for (int loop = 26; loop <= 38; loop++)
	{
		Pack[loop].suit = CLUBS;
		Pack[loop].value = loop + 1;
		Pack[loop].score = loop + 1;

	}
	//score for Jack, Queen, King
	Pack[36].score = 10;
	Pack[37].score = 10;
	Pack[38].score = 10;
}

void SetupSpades()
{
	for (int loop = 39; loop <= 51; loop++)
	{
		Pack[loop].suit = SPADES;
		Pack[loop].value = loop + 1;
		Pack[loop].score = loop + 1;

	}
	//score for Jack, Queen, King
	Pack[49].score = 10;
	Pack[50].score = 10;
	Pack[51].score = 10;
}

void displayPack()
{
	for (int loop = 0; loop < NUMBER_OF_CARDS; loop++)
	{
		cout << "Suit = " << Pack[loop].suit;
		cout << "Score = " << Pack[loop].score;
		cout << "Value = " << Pack[loop].value;
		cout << endl;
	}
}

void ShufflePack()
{

	srand(time(0));


	for (int shuffle = 0; shuffle < 100; shuffle++)
	{
		int rndNum1 = rand() % 51;
		int rndNum2 = rand() % 51;

	}


}
well... how does a round of playing blackjack go?
its something like
deal 2 cards to each player, one hidden, one shown.

check for blackjacks in all the hands. anyone with is immediate winner or if multiple, deal with ties. some rule sets make pure blackjack pay out a % extra above the bet value, while a 21 total using more than 2 cards is the bet value on a win.

each player gets a turn and can
end turn
possibly split (2 of the same card, takes a second bet for the second hand)
hit
double (double bet, takes 1 card and stops can't hit )
etc

then the next player.
the house can't split or double etc, it just plays its 1 hand.

after all that find the winner and adjust the money
repeat until bored

reading that, it looks like you need routines or logic to check for blackjacks (if this and that.. do something and this hand is over), mess with the money for the players (an issue on split and when a round ends and when a round begins), give the human player the option to split/double/hit/stop (a menu in the play loop?) figure out the winner (could also just be if/then or a loop or simple logic) and so on. Unsaid but you want your house to have some simple AI, which could be as simple as 'hit until 17+ then stand' or 'hit until beats players or busted'). And you need busted logic too (go over 21, that player loses and ends turn).



Last edited on
I know how blackjack is played but I don't know how to implement the code for the playing part of it
A very simple simple way would be to use two vectors, one for the player's cards and on for the dealer's cards.
Dealing the cards would just involve adding a card to the vector.

Personally I would go for a OO solutions with classes Player, Dealer, Hand, Deck.
If you do a little research I am sure you will find plenty of examples.
Start small. Create the data structures to represent the hands of each player. Then write code to deal 2 cards to them and check for blackjack.
Topic archived. No new replies allowed.