-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCant_stop.cpp
410 lines (358 loc) · 15.9 KB
/
Cant_stop.cpp
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#include <iostream>
#include <string>
#include <random>
#include <thread>
#include <chrono>
#include <ctime>
#include <cstdlib>
using namespace std;
int roll_die_1(){
return rand()%6 + 1;
}
int roll_die_2(){
return rand()%6 + 1;
}
int roll_die_3(){
return rand()%6 + 1;
}
int roll_die_4(){
return rand()%6 + 1;
}
void print_4_dice_result(int *roll_die_1, int *roll_die_2, int *roll_die_3, int *roll_die_4){
cout << "Dice 1 rolls: "<<*roll_die_1<<"\n";
cout << "Dice 2 rolls: "<<*roll_die_2<<"\n";
cout << "Dice 3 rolls: "<<*roll_die_3<<"\n";
cout << "Dice 4 rolls: "<<*roll_die_4<<"\n";
}
void Clear_Terminal(){
cout << "\n\n\n\n\n\n\n\n\n";
}
void End_formater(){
cout << "\n\n\n";
}
void Dice_Randomiser(bool *run_game, int *dice1, int *dice2, int *dice3, int *dice4){
srand(time(0));
while (*run_game == true){
this_thread::sleep_for(chrono::milliseconds(10));
*dice1 = roll_die_1();
*dice2 = roll_die_2();
*dice3 = roll_die_3();
*dice4 = roll_die_4();
}
}
bool check_for_busting(){
return true;
}
void Player_1_turn(){
}
void Player_2_turn(){
}
int main(){
bool run_game = true;
bool run_main = true;
int player_1_ID = 1;
int player_2_ID = 2;
int Player_1_SET = 3;
int Player_2_SET = 4;
// Empty game board at the start
int board_col_2[2] = {0, 0};
int board_col_3[4] = {0, 0, 0, 0};
int board_col_4[6] = {0, 0, 0, 0, 0, 0};
int board_col_5[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int board_col_6[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int board_col_7[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int board_col_8[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int board_col_9[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int board_col_10[6] = {0, 0, 0, 0, 0, 0};
int board_col_11[4] = {0, 0, 0, 0};
int board_col_12[2] = {0, 0};
// The randomised future dices, these dices are rolled on another thread non_stop
int dice_1_next = 0;
int dice_2_next = 0;
int dice_3_next = 0;
int dice_4_next = 0;
// After player 1 makes the decision, these dices are then selected from the future dices from the other thread
int dice_1_p1 = 0;
int dice_2_p1 = 0;
int dice_3_p1 = 0;
int dice_4_p1 = 0;
// After player 1 makes the decision, these dices are then selected from the future dices from the other thread
int dice_1_p2 = 0;
int dice_2_p2 = 0;
int dice_3_p2 = 0;
int dice_4_p2 = 0;
// running thread
thread Run____Dice_Randomiser___THREAD(Dice_Randomiser,&run_game, &dice_1_next, &dice_2_next, &dice_3_next, &dice_4_next);
Run____Dice_Randomiser___THREAD.detach();
string player_1_decision = "";
string player_2_decision = "";
// The main while loop
while (run_main == true){
Clear_Terminal();
cout << "\n\n P1 Roll a dice! enter: r / R / roll\n\n ";
cin >> player_1_decision;
if (cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
player_1_decision = "";
}
int player_1_pair_selection_first = 0;
int player_1_pair_selection_second = 0;
int two_column_progress = 0;
int three_column_progress = 0;
int four_column_progress = 0;
int five_column_progress = 0;
int six_column_progress = 0;
int seven_column_progress = 0;
int eight_column_progress = 0;
int nine_column_progress = 0;
int ten_column_progress = 0;
int eleven_column_progress = 0;
int twelve_column_progress = 0;
if (player_1_decision == "r" || player_1_decision == "R" || player_1_decision == "roll"){
dice_1_p1 = dice_1_next;
dice_2_p1 = dice_2_next;
dice_3_p1 = dice_3_next;
dice_4_p1 = dice_4_next;
cout << "\n\n There are 4 dice pair combinations: \n";
cout << " 1 " << dice_1_p1 <<" and "<< dice_2_p1 << " ("<<dice_1_p1+dice_2_p1<< ") \n";
cout << " 2 " << dice_3_p1 <<" and "<< dice_4_p1 << " ("<<dice_3_p1+dice_4_p1<< ") \n";
cout << " 3 " << dice_2_p1 <<" and "<< dice_3_p1 << " ("<<dice_2_p1+dice_3_p1<< ") \n";
cout << " 4 " << dice_1_p1 <<" and "<< dice_4_p1 << " ("<<dice_1_p1+dice_4_p1<< ") \n";
// if ((dice_1_p1 + dice_2_p1) != )
cout << "\n\n Select first pair combination from above: \n ";
cin >> player_1_pair_selection_first;
if (cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
player_1_pair_selection_first = 0;
}
cout << "\n\n Select second pair combination from above: \n ";
cin >> player_1_pair_selection_second;
if (cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
player_1_pair_selection_second = 0;
}
if (player_1_pair_selection_first == player_1_pair_selection_second){
cout << "\n\n The second selection cannot be the same! Try again . . .\n ";
cin >> player_1_pair_selection_second;
if (cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
player_1_pair_selection_second = 0;
}
}
switch (player_1_pair_selection_first){
case 2:
board_col_2[two_column_progress] = 1;
two_column_progress++;
break;
case 3:
board_col_3[three_column_progress] = 1;
three_column_progress++;
break;
case 4:
board_col_4[four_column_progress] = 1;
four_column_progress++;
break;
case 5:
board_col_5[five_column_progress] = 1;
five_column_progress++;
break;
case 6:
board_col_6[six_column_progress] = 1;
six_column_progress++;
break;
case 7:
board_col_7[seven_column_progress] = 1;
seven_column_progress++;
break;
case 8:
board_col_8[eight_column_progress] = 1;
eight_column_progress++;
break;
case 9:
board_col_9[nine_column_progress] = 1;
nine_column_progress++;
break;
case 10:
board_col_10[ten_column_progress] = 1;
ten_column_progress++;
break;
case 11:
board_col_11[eleven_column_progress] = 1;
eleven_column_progress++;
break;
case 12:
board_col_12[twelve_column_progress] = 1;
twelve_column_progress++;
break;
}
switch (player_1_pair_selection_second){
case 2:
board_col_2[two_column_progress] = 1;
two_column_progress++;
break;
case 3:
board_col_3[three_column_progress] = 1;
three_column_progress++;
break;
case 4:
board_col_4[four_column_progress] = 1;
four_column_progress++;
break;
case 5:
board_col_5[five_column_progress] = 1;
five_column_progress++;
break;
case 6:
board_col_6[six_column_progress] = 1;
six_column_progress++;
break;
case 7:
board_col_7[seven_column_progress] = 1;
seven_column_progress++;
break;
case 8:
board_col_8[eight_column_progress] = 1;
eight_column_progress++;
break;
case 9:
board_col_9[nine_column_progress] = 1;
nine_column_progress++;
break;
case 10:
board_col_10[ten_column_progress] = 1;
ten_column_progress++;
break;
case 11:
board_col_11[eleven_column_progress] = 1;
eleven_column_progress++;
break;
case 12:
board_col_12[twelve_column_progress] = 1;
twelve_column_progress++;
break;
}
cout << "\n Enter your selection: \n ";
}
cout << "\n\n P2 Roll a dice! enter r/R/roll\n\n ";
cin >> player_2_decision;
if (cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
player_2_decision = "";
}
}
End_formater();
return 0;
}
// int closet_to_7_difference[6];
// closet_to_7_difference[0] = (dice_1_p1+dice_2_p1)-7;
// closet_to_7_difference[0] = abs(closet_to_7_difference[0]);
// cout << " the abs number is now: "<<closet_to_7_difference[0]<<"\n";
// closet_to_7_difference[1] = (dice_3_p1+dice_4_p1)-7;
// closet_to_7_difference[1] = abs(closet_to_7_difference[1]);
// cout << " the abs number is now: "<<closet_to_7_difference[1]<<"\n";
// closet_to_7_difference[2] = (dice_2_p1+dice_3_p1)-7;
// closet_to_7_difference[2] = abs(closet_to_7_difference[2]);
// cout << " the abs number is now: "<<closet_to_7_difference[2]<<"\n";
// closet_to_7_difference[3] = (dice_1_p1+dice_4_p1)-7;
// closet_to_7_difference[3] = abs(closet_to_7_difference[3]);
// cout << " the abs number is now: "<<closet_to_7_difference[3]<<"\n";
// closet_to_7_difference[4] = (dice_1_p1+dice_3_p1)-7;
// closet_to_7_difference[4] = abs(closet_to_7_difference[4]);
// cout << " the abs number is now: "<<closet_to_7_difference[4]<<"\n";
// closet_to_7_difference[5] = (dice_4_p1+dice_2_p1)-7;
// closet_to_7_difference[5] = abs(closet_to_7_difference[5]);
// cout << " the abs number is now: "<<closet_to_7_difference[5]<<"\n";
int closet_to_7[6] = {(dice_1_p1+dice_2_p1), (dice_3_p1+dice_4_p1), (dice_2_p1+dice_3_p1), (dice_1_p1+dice_4_p1), (dice_1_p1+dice_3_p1), (dice_4_p1+dice_2_p1)};
cout << "\n\n There are 6 dice pair combinations: \n";
cout << " 1 " << dice_1_p1 <<" and "<< dice_2_p1 << " ("<<dice_1_p1+dice_2_p1<< ") \n";
cout << " 2 " << dice_3_p1 <<" and "<< dice_4_p1 << " ("<<dice_3_p1+dice_4_p1<< ") \n";
cout << " 3 " << dice_2_p1 <<" and "<< dice_3_p1 << " ("<<dice_2_p1+dice_3_p1<< ") \n";
cout << " 4 " << dice_1_p1 <<" and "<< dice_4_p1 << " ("<<dice_1_p1+dice_4_p1<< ") \n";
cout << " 5 " << dice_1_p1 <<" and "<< dice_3_p1 << " ("<<dice_1_p1+dice_3_p1<< ") \n";
cout << " 6 " << dice_4_p1 <<" and "<< dice_2_p1 << " ("<<dice_4_p1+dice_2_p1<< ") \n";
int closet_to_7_difference[6];
closet_to_7_difference[0] = (dice_1_p1+dice_2_p1)-7;
closet_to_7_difference[0] = abs(closet_to_7_difference[0]);
cout << " the abs number is now: "<<closet_to_7_difference[0]<<"\n";
closet_to_7_difference[1] = (dice_3_p1+dice_4_p1)-7;
closet_to_7_difference[1] = abs(closet_to_7_difference[1]);
cout << " the abs number is now: "<<closet_to_7_difference[1]<<"\n";
closet_to_7_difference[2] = (dice_2_p1+dice_3_p1)-7;
closet_to_7_difference[2] = abs(closet_to_7_difference[2]);
cout << " the abs number is now: "<<closet_to_7_difference[2]<<"\n";
closet_to_7_difference[3] = (dice_1_p1+dice_4_p1)-7;
closet_to_7_difference[3] = abs(closet_to_7_difference[3]);
cout << " the abs number is now: "<<closet_to_7_difference[3]<<"\n";
closet_to_7_difference[4] = (dice_1_p1+dice_3_p1)-7;
closet_to_7_difference[4] = abs(closet_to_7_difference[4]);
cout << " the abs number is now: "<<closet_to_7_difference[4]<<"\n";
closet_to_7_difference[5] = (dice_4_p1+dice_2_p1)-7;
closet_to_7_difference[5] = abs(closet_to_7_difference[5]);
cout << " the abs number is now: "<<closet_to_7_difference[5]<<"\n";
bool swapped_first = false;
for (int i = 0; i < 6-1; i++){
swapped_first = false;
for (int j = 0; j < 6-i-1; j++){
if (closet_to_7_difference[j] > closet_to_7_difference[j+1]){
swap(closet_to_7_difference[j], closet_to_7_difference[j+1]);
swapped_first = true;
}
}
}
cout << "\n\n";
for (int j = 0; j < 6; j++){
cout << " "<<closet_to_7_difference[j]<<"\n";
}
cout << "\n\n";
bool swapped = false;
for (int i = 0; i < 6-1; i++){
swapped = false;
for (int j = 0; j < 6-i-1; j++){
if (closet_to_7[j] > closet_to_7[j+1]){
swap(closet_to_7[j], closet_to_7[j+1]);
swapped = true;
}
}
}
cout << "\n\n";
for (int j = 0; j < 6; j++){
cout << " "<<closet_to_7[j]<<"\n";
}
cout << "\n\n";
int closet_to_7[6] = {(dice_1_p1+dice_2_p1), (dice_3_p1+dice_4_p1), (dice_2_p1+dice_3_p1), (dice_1_p1+dice_4_p1), (dice_1_p1+dice_3_p1), (dice_4_p1+dice_2_p1)};
bool swapped = false;
for (int i = 0; i < 6-1; i++){
swapped = false;
for (int j = 0; j < 6-i-1; j++){
if (closet_to_7[j] > closet_to_7[j+1]){
swap(closet_to_7[j], closet_to_7[j+1]);
swapped = true;
}
}
}
int closet_first = getNearestElement(closet_to_7,6,7);
for (int j = 0; j < 6; j++){
if (closet_first == closet_to_7[j]){
closet_to_7[j] = -99;
}
}
bool swapped_second = false;
for (int i = 0; i < 6-1; i++){
swapped_second = false;
for (int j = 0; j < 6-i-1; j++){
if (closet_to_7[j] > closet_to_7[j+1]){
swap(closet_to_7[j], closet_to_7[j+1]);
swapped_second = true;
}
}
}
int closet_second = getNearestElement(closet_to_7,6,7);
player_1_pair_selection_first = closet_first;
player_1_pair_selection_second = closet_second;
cout << "\n\n First closet dice pair to 7: "<<player_1_pair_selection_first<<"\n";
cout << "\n\n Second closet dice pair to 7: "<<player_1_pair_selection_second<<"\n";