-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoker.cpp
More file actions
268 lines (251 loc) · 9.85 KB
/
Poker.cpp
File metadata and controls
268 lines (251 loc) · 9.85 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//Zainspirowane pokerem z wiedzmina 2
#include <iostream>
#include <ctime>
#include <vector>
#include <algorithm>
#include <unordered_map>
class Dice {
public:
int val = 1;
int rollC = 0;
bool isSelected = false;
bool canBeSelected = true;
int order;
int roll() {
val = (rand() % 6) + 1;
rollC++;
if (rollC == 2) {
canBeSelected = false;
}
return val;
}
int wys() {
std::cout << std::boolalpha;
std::cout << "Kosc nr: " << 1 + order << " Wartosc: " << val
<< " Wybrana?: " << isSelected << " Mozna wybrac?: "
<< canBeSelected << " RC: " << rollC << '\n';
return 0;
}
};
struct GameResult {
bool straight;
bool fiveOK;
bool fourOK;
bool house;
bool threeOK;
bool twoPair;
bool pair;
std::vector<std::vector<int> > groups;
std::vector<int> values;
};
int main()
{
srand(time(NULL));
int arr[5];
Dice dice[5];
for (int i = 0; i < 5; i++) {
dice[i].order = i;
}
std::cout << "Oto twoje kosci!\n";
std::cout << "----------------------------------------------------------------------------------\n";
for (int i = 0; i < 5; i++) {
dice[i].roll();
dice[i].wys();
if (i == 4) {
std::cout << "----------------------------------------------------------------------------------\n";
}
}
label1:
std::cout << "1.Wybierz kosc do przerzucenia\n";
std::cout << "2.Rzuc koscmi!\n";
std::cout << "3.Wyswietl kosci\n";
std::cout << "4.Skoncz runde\n";
std::cout << "5.Wyjscie\n";
std::cout << "----------------------------------------------------------------------------------\n";
int menu, selection;
std::cin >> menu;
while (true) {
switch (menu) {
case 1:
std::cout << "----------------------------------------------------------------------------------\n";
std::cout << "Wybierz kosci ktore chcesz zaznaczyc (po kolei)\n";
std::cout << "Wybranie zaznaczonej kosci odznaczy ja\n";
std::cout << "Aby wyswietlic kosce wpisz 6.\n";
std::cout << "Gdy skonczysz wpisz 7.\n";
std::cout << "----------------------------------------------------------------------------------\n";
for (int i = 0; i < 5; i++) {
dice[i].wys();
if (i == 4) {
std::cout << "----------------------------------------------------------------------------------\n";
}
}
while (true) {
std::cin >> selection;
switch (selection) {
case 1:
case 2:
case 3:
case 4:
case 5:
std::cout << "Wybrano kosc: " << selection << "\n";
if (dice[selection - 1].rollC < 2) {
if (dice[selection - 1].canBeSelected == true) {
dice[selection - 1].isSelected = true;
dice[selection - 1].canBeSelected = false;
}
else {
std::cout << "Ta kosc byla juz wybrana wiec zostanie odznaczona!\n";
dice[selection - 1].isSelected = false;
if (dice[selection - 1].rollC < 2) {
dice[selection - 1].canBeSelected = true;
}
}
}
else {
std::cout << "Mozna tylko raz przerzucic kosc!\n";
}
break;
case 6:
for (int i = 0; i < 5; i++) {
dice[i].wys();
if (i == 4) {
std::cout << "----------------------------------------------------------------------------------\n";
}
}
break;
case 7:
std::cout << "Zakonczono wybieranie\n";
goto label1;
break;
default:
std::cout << "Podaj liczbe od 1 do 7\n";
}
}
break;
case 2:
std::cout << "**********************************************************************************\n";
std::cout << "*********************************Rzucamy!*****************************************\n";
std::cout << "**********************************************************************************\n";
for (int i = 0; i < 5; i++) {
if (dice[i].isSelected == true) {
dice[i].roll();
dice[i].isSelected = false;
if (dice[i].rollC < 2) {
dice[i].canBeSelected = true;
}
}
}
for (int i = 0; i < 5; i++) {
arr[i] = dice[i].val;
}
for (int i = 0; i < 5; i++) {
dice[i].wys();
if (i == 4) {
std::cout << "----------------------------------------------------------------------------------\n";
}
}
std::cout << "1.Wybierz kosc do przerzucenia\n";
std::cout << "2.Rzuc koscmi!\n";
std::cout << "3.Wyswietl kosci\n";
std::cout << "4.Skoncz runde\n";
std::cout << "5.Wyjscie\n";
std::cout << "----------------------------------------------------------------------------------\n";
std::cin >> menu;
break;
case 3:
std::cout << "Oto twoje kosci!\n";
std::cout << "----------------------------------------------------------------------------------\n";
for (int i = 0; i < 5; i++) {
dice[i].wys();
if (i == 4) {
std::cout << "----------------------------------------------------------------------------------\n";
}
}
std::cout << "1.Wybierz kosc do przerzucenia\n";
std::cout << "2.Rzuc koscmi!\n";
std::cout << "3.Wyswietl kosci\n";
std::cout << "4.Skoncz runde\n";
std::cout << "5.Wyjscie\n";
std::cout << "----------------------------------------------------------------------------------\n";
std::cin >> menu;
break;
case 4: {
std::cout << "Twoje kosci to...\n";
for (int i = 0; i < 5; i++) {
arr[i] = dice[i].val;
}
std::sort(arr, arr + 5);
for (int i = 0; i < 5; i++) {
std::cout << arr[i];
}
std::cout << '\n';
std::unordered_map<int, std::vector<int> > groups;
for (int i = 0; i < 5; i++) {
groups[arr[i]].push_back(arr[i]);
}
GameResult result;
result.straight = false;
result.fiveOK = false;
result.fourOK = false;
result.house = false;
result.threeOK = false;
result.twoPair = false;
result.pair = false;
std::unordered_map<int, std::vector<int> >::iterator it;
for (it = groups.begin(); it != groups.end(); ++it) {
if (it->second.size() > 1) {
result.groups.push_back(it->second);
result.values.push_back(it->first);
}
}
for (int i = 0; i < result.groups.size(); i++) {
int size = result.groups[i].size();
if (size == 5) result.fiveOK = true;
else if (size == 4) result.fourOK = true;
else if (size == 3) result.threeOK = true;
else if (size == 2) {
if (result.pair) result.twoPair = true;
else result.pair = true;
}
}
if (result.threeOK && result.pair) {
result.house = true;
}
if (arr[4] - arr[3] == 1 && arr[3] - arr[2] == 1 && arr[2] - arr[1] == 1 && arr[1] - arr[0] == 1) {
result.straight = true;
}
if (result.fiveOK) std::cout << "Piatka!\n";
else if (result.fourOK) std::cout << "Czworka!\n";
else if (result.house) std::cout << "Full!\n";
else if (result.straight) std::cout << "Strit!\n";
else if (result.threeOK) std::cout << "Trójka!\n";
else if (result.twoPair) std::cout << "Dwie pary!\n";
else if (result.pair) std::cout << "Para!\n";
else std::cout << "Wysoka karta: " << arr[4] << "\n";
std::cout << "1.Wybierz kosc do przerzucenia\n";
std::cout << "2.Rzuc koscmi!\n";
std::cout << "3.Wyswietl kosci\n";
std::cout << "4.Skoncz runde\n";
std::cout << "5.Wyjscie\n";
std::cout << "----------------------------------------------------------------------------------\n";
std::cin >> menu;
break;
}
case 5:
std::cout << "narazie";
return 1;
default:
std::cout << "Podaj liczbe od 1 do 5\n";
std::cout << "----------------------------------------------------------------------------------\n";
std::cout << "1.Wybierz kosc do przerzucenia\n";
std::cout << "2.Rzuc koscmi!\n";
std::cout << "3.Wyswietl kosci\n";
std::cout << "4.Skoncz runde\n";
std::cout << "5.Wyjscie\n";
std::cout << "----------------------------------------------------------------------------------\n";
std::cin >> menu;
break;
}
}
return 0;
}