Holdem problem using basic C++

First off I am not asking for a written script to steal and pass my c++ course. A sample script would help me by looking at it figuring out what I need to do.I need to learn the material and hope to be guided in the right direction.

Please do not post a reply if you have not completely read my post.

This is my first c++ course and have been given a project for a major grade.

We had the choice of picking our own project whether it would be simple or difficult. I ended up choosing texas holdem which turns out its one of the more difficult ones for what we have been taught. Since I was doing good in the course I quickly envisioned it or how I could do it and how I wanted it, I actually thought I could make it a heads up game with the dealer playing the game exactly as I would.

I started the draft project and off the bat I ran into a problem I never thought of when thinking of choosing holdem, I cant figure out how to make the dealing of the cards not repeat. The dealer and player are dealt 2 cards, then the flop is dealt 3 then the turn and river, I cannot have the cards repeat when they are being dealt out.

I went into the index of our book and came accross the random_shuffle algorithm which could help me out with the problem. I asked the instructor a question about it and it turns out I cant use it.

We are only able to use material we have learned in the class and no other. The only things we have been taught are the basics, "if statements, loops, random numbers, functions, and arrays", basically in this order. To get a sense of the level I am at I am able to create a simple blackjack game something I didnt have much problems with, we created it before learning arrays.

The code I have here I started it right before we began learning about arrays, Its very simple I just did it to get an understanding about what I was going to be facing, so its not complete at all and I know I have the wrong rand num modules for the cards I just put it like this to test out the code.

I am still understanding arrays while I can see an array and know what it does I cant create one out of memory yet, it didnt help that we never had any assigments or tests over them. Using arrays with the holdem game should help me out I just need to know how to get started.

The main question I have here right now is how do I make the dealing of the cards not repeat, I know I am going to face another problem when I come accross the suits, dont laugh at my code I am a beginner lol.

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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  #include<iostream>
#include<string>
#include<time.h>

using namespace std;
/*[4][12]
cards[52]
used[52]={0}; 
This is just a note I added to myself on how I might use arrays*/

int main()
{
	
	srand(time(0));
	int playercard1=rand()%10+1;
	int playercard2=rand()%10+1;
	int dealercard1=rand()%10+1;
	int dealercard2=rand()%10+1;
	int flopcard1=rand()%10+1;
	int flopcard2=rand()%10+1;
	int flopcard3=rand()%10+1;
	int turncard=rand()%10+1;
	int rivercard=rand()%10+1;
	int dealerbet;
	int dealerraise;
	int playerbet;
	int playerraise;
	int playerfunds=100;
	int dealerfunds=100;
	int smallblind=1;
	int bigblind=2;
	char choice;

	cout<<" -Player cards-"<<endl;

	if (playercard1==1)
		cout<<"   [As] ";
	else if (playercard1==2)
		cout<<"   [Ah] ";
	else if (playercard1==3)
		cout<<"   [Ad] ";
	else if (playercard1==4)
		cout<<"   [Ac] ";
	else if (playercard1==5)
		cout<<"   [2s] ";
	else if (playercard1==6)
		cout<<"   [2h] ";
	else if (playercard1==7)
		cout<<"   [2d] ";
	else if (playercard1==8)
		cout<<"   [2c] ";
	else if (playercard1==9)
		cout<<"   [3s] ";
	else if (playercard1==10)
		cout<<"   [3h] ";
	else if (playercard1==11)
		cout<<"   [3d] ";
	else if (playercard1==12)
		cout<<"   [3c] ";

	if (playercard2==1)
		cout<<"[As]"<<endl;
	else if (playercard2==2)
		cout<<"[Ah]"<<endl;
	else if (playercard2==3)
		cout<<"[Ad]"<<endl;
	else if (playercard2==4)
		cout<<"[Ac]"<<endl;
	else if (playercard2==5)
		cout<<"[2s]"<<endl;
	else if (playercard2==6)
		cout<<"[2h]"<<endl;
	else if (playercard2==7)
		cout<<"[2d]"<<endl;
	else if (playercard2==8)
		cout<<"[2c]"<<endl;
	else if (playercard2==9)
		cout<<"[3s]"<<endl;
	else if (playercard2==10)
		cout<<"[3h]"<<endl;
	else if (playercard2==11)
		cout<<"[3d]"<<endl;
	else if (playercard2==12)
		cout<<"[3c]"<<endl;

	cout<<"    $"<<playerfunds<<".00"<<endl;

	cout<<"   "<<endl;
	cout<<"    -Flop-"<<endl;
	if (flopcard1==1)
		cout<<"[As] ";
	else if (flopcard1==2)
		cout<<"[Ah] ";
	else if (flopcard1==3)
		cout<<"[Ad] ";
	else if (flopcard1==4)
		cout<<"[Ac] ";
	else if (flopcard1==5)
		cout<<"[2s] ";
	else if (flopcard1==6)
		cout<<"[2h] ";
	else if (flopcard1==7)
		cout<<"[2d] ";
	else if (flopcard1==8)
		cout<<"[2c] ";
	else if (flopcard1==9)
		cout<<"[3s] ";
	else if (flopcard1==10)
		cout<<"[3h] ";
	else if (flopcard1==11)
		cout<<"[3d] ";
	else if (flopcard1==12)
		cout<<"[3c] ";

	if (flopcard2==1)
		cout<<"[As] ";
	else if (flopcard2==2)
		cout<<"[Ah] ";
	else if (flopcard2==3)
		cout<<"[Ad] ";
	else if (flopcard2==4)
		cout<<"[Ac] ";
	else if (flopcard2==5)
		cout<<"[2s] ";
	else if (flopcard2==6)
		cout<<"[2h] ";
	else if (flopcard2==7)
		cout<<"[2d] ";
	else if (flopcard2==8)
		cout<<"[2c] ";
	else if (flopcard2==9)
		cout<<"[3s] ";
	else if (flopcard2==10)
		cout<<"[3h] ";
	else if (flopcard2==11)
		cout<<"[3d] ";
	else if (flopcard2==12)
		cout<<"[3c] ";

	if (flopcard3==1)
		cout<<"[As]"<<endl;
	else if (flopcard3==2)
		cout<<"[Ah]"<<endl;
	else if (flopcard3==3)
		cout<<"[Ad]"<<endl;
	else if (flopcard3==4)
		cout<<"[Ac]"<<endl;
	else if (flopcard3==5)
		cout<<"[2s]"<<endl;
	else if (flopcard3==6)
		cout<<"[2h]"<<endl;
	else if (flopcard3==7)
		cout<<"[2d]"<<endl;
	else if (flopcard3==8)
		cout<<"[2c]"<<endl;
	else if (flopcard3==9)
		cout<<"[3s]"<<endl;
	else if (flopcard3==10)
		cout<<"[3h]"<<endl;
	else if (flopcard3==11)
		cout<<"[3d]"<<endl;
	else if (flopcard3==12)
		cout<<"[3c]"<<endl;

	cout<<"  "<<endl;
	cout<<" -Dealer cards-"<<endl;

	if (dealercard1==1)
		cout<<"   [As] ";
	else if (dealercard1==2)
		cout<<"   [Ah] ";
	else if (dealercard1==3)
		cout<<"   [Ad] ";
	else if (dealercard1==4)
		cout<<"   [Ac] ";
	else if (dealercard1==5)
		cout<<"   [2s] ";
	else if (dealercard1==6)
		cout<<"   [2h] ";
	else if (dealercard1==7)
		cout<<"   [2d] ";
	else if (dealercard1==8)
		cout<<"   [2c] ";
	else if (dealercard1==9)
		cout<<"   [3s] ";
	else if (dealercard1==10)
		cout<<"   [3h] ";
	else if (dealercard1==11)
		cout<<"   [3d] ";
	else if (dealercard1==12)
		cout<<"   [3c] ";

	if (dealercard2==1)
		cout<<"[As]"<<endl;
	else if (dealercard2==2)
		cout<<"[Ah]"<<endl;
	else if (dealercard2==3)
		cout<<"[Ad]"<<endl;
	else if (dealercard2==4)
		cout<<"[Ac]"<<endl;
	else if (dealercard2==5)
		cout<<"[2s]"<<endl;
	else if (dealercard2==6)
		cout<<"[2h]"<<endl;
	else if (dealercard2==7)
		cout<<"[2d]"<<endl;
	else if (dealercard2==8)
		cout<<"[2c]"<<endl;
	else if (dealercard2==9)
		cout<<"[3s]"<<endl;
	else if (dealercard2==10)
		cout<<"[3h]"<<endl;
	else if (dealercard2==11)
		cout<<"[3d]"<<endl;
	else if (dealercard2==12)
		cout<<"[3c]"<<endl;

	cout<<"    $"<<dealerfunds<<".00"<<endl;
	
	cout<<"  "<<endl;

	return 0;
}
Last edited on
Hiya. That's quite the sticky situation you've got.

Personally, I rather hate it when professors say "you can only use what you've learned in this class", because it's an effective way of discouraging learning outside of the class. Sadly, there's little that can be done about it.

You have options.

1. This is a horribly hackish solution. Maintain an array (1d or 2d, each choice has its benefits) to store whether or not a card has been dealt. Have a function that gets cards that generates a random number representing a card checks against this array, and if a certain card has already been dealt, recalculate the random number.

2. Implement your own random shuffling function. Then, when you need a card, have a counter that is initialized to the size of your array minus one, read the element at the subscript equal to the counter's value, and decrement the counter. To quote a psuedocode example from Wikipedia on the Fisher-Yates shuffle:
1
2
3
4
To shuffle an array a of n elements (indices 0..n-1):
  for i from n − 1 downto 1 do
       j ← random integer with 0 ≤ j ≤ i
       exchange a[j] and a[i]

http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

Good luck!

-Albatross
Last edited on
Personally, I rather hate it when professors say "you can only use what you've learned in this class", because it's an effective way of discouraging learning outside of the class.

It also hinders students who just want to go online and copy/paste some code that someone else wrote. Right now, I suspect that's by far the bigger problem.
Topic archived. No new replies allowed.