-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.h
More file actions
592 lines (484 loc) · 41.3 KB
/
Game.h
File metadata and controls
592 lines (484 loc) · 41.3 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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
// Project Card Game
// by Pierre
// and Samuel
#ifndef PROJECT_CARD_GAME_GAME_H
#define PROJECT_CARD_GAME_GAME_H
#include <vector>
#include "Card.h"
#include "Player.h"
class Game
{
vector<Card> _reserve;
Player _player1;
Player _player2;
public:
/**
*************************************************************************************************
* *
* Description *
* =========== *
* This constructor creates a new game instance with an empty reserve, and default *
* player instances. *
* *
* Input parameters *
* ==================== *
* (none) *
* *
* Output parameters *
* ==================== *
* @return A new Game object with default values for its attributes. *
* *
*************************************************************************************************
*/
Game();
/**
*************************************************************************************************
* *
* Description *
* =========== *
* This constructor creates a new game instance with a specified reserve and player instances. *
* *
* Input parameters *
* ==================== *
* @param reserve The game's reserve of cards. *
* @param player1 The first player in the game. *
* @param player2 The second player in the game. *
* *
* Output parameters *
* ==================== *
* @return A new Game object with default values for its attributes. *
* *
*************************************************************************************************
*/
Game(const vector<Card> &reserve, Player &player1, Player &player2);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* returns if the game has ended or not, if it has, the player object taken as parameter *
* takes the information of the winner between both player *
* *
* Input parameters *
* ==================== *
* @param winner object that is updated when the game ends *
* *
* Output parameters *
* ==================== *
* @return a boolean which indicates whether the game has ended or not *
* @param winner object that is updated when the game ends *
* *
*************************************************************************************************
*/
bool ended(Player &winner) const;
/*
*************************************************************************************************
* *
* Description *
* =========== *
* plays a round of the game by calling the function playsACard *
* *
* Input parameters *
* ==================== *
* (none) *
* *
* Output parameters *
* ==================== *
* no visible output, but it actualises the stats of the players depending on *
* the result of the function playsACard *
* *
*************************************************************************************************
*/
void playsARound();
/*
*************************************************************************************************
* *
* Description *
* =========== *
* plays a round of the game by calling the function playsARound *
* *
* Input parameters *
* ==================== *
* no parameters *
* *
* Output parameters *
* ==================== *
* no visible output, but it actualises the stats of the players depending on *
* the result of the function playsACard *
* *
*************************************************************************************************
*/
void operator++();
/**
*************************************************************************************************
* *
* Description *
* =========== *
* returns if the game is finished *
* *
* Input parameters *
* ==================== *
* (none) *
* *
* Output parameters *
* ==================== *
* @returns a boolean which is set to true when game has ended, false when game has not ended *
* *
*************************************************************************************************
*/
bool IsGameFinished() const;
/**
*************************************************************************************************
* *
* Description *
* =========== *
* returns a specific integer depending on the winner of the game *
* we know if the game has ended by calling the function ended with a default Player object *
* so when the function ended has ended ;) the default object is set with the data of the winner *
* *
* Input parameters *
* ==================== *
* no parameters *
* *
* Output parameters *
* ==================== *
* @returns 1 if player 1 won the game and -1 if player 2 won and 0 if it's a draw *
* *
*************************************************************************************************
*/
int winner();
/**
*************************************************************************************************
* *
* Description *
* =========== *
* Reads the card data from a file and stores them in the reserve of the game object. *
* The cards are sorted in alphabetical order based on their name. *
* *
* *
* Input parameters *
* ==================== ¯\_(¨_¨)_/¯ *
* @param filename which is the file name | | *
* / \ *
* Output parameters *
* ==================== *
* @throws out_of_range If the file cannot be opened *
* *
*************************************************************************************************
**/
void fillReserve(const string &filename);
// The following methods are not in the instructions, but we had them because they are useful many times
/**
*************************************************************************************************
* *
* *
* Description : *
* =========== *
* compare the actual reserve with another reserve given in argument *
* *
* *
* Input parameters *
* ==================== *
* @param vector -> the reserve which will be compared with the targeted object's reserve *
* *
* *
* Output parameters *
* ==================== *
* boolean so true if they're the same, false if they ain't *
* *
*************************************************************************************************
*/
bool compareReserve(const vector<Card> &vector) const;
/**
*************************************************************************************************
* *
* Description : *
* =========== *
* modify the prestige of player2 setting it to num by calling the Player function *
* modifyPrestige() *
* *
* Input parameters *
* ==================== *
* @param num -> the amount of prestige we want to set to the player two *
* *
* Output parameters *
* ==================== *
* (none) *
* *
*************************************************************************************************
*/
void modifyPlayerTwoPrestige(int num);
/**
*************************************************************************************************
* *
* Description : *
* =========== *
* modify the prestige of player1 setting it to num by calling the Player function *
* modifyPrestige() *
* *
* Input parameters *
* ==================== *
* @param num -> the amount of prestige we want to set to the player one *
* *
* Output parameters *
* ==================== *
* (none) *
* *
*************************************************************************************************
*/
void modifyPlayerOnePrestige(int num);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* Clear the player's two deck *
* *
* Input parameters *
* ==================== *
* (none) *
* *
* Output parameters *
* ==================== *
* (none) *
* *
*************************************************************************************************
*/
void clearPlayerTwoDeck();
/**
*************************************************************************************************
* *
* Description *
* =========== *
* compares the actual game with the game taken as parameter *
* *
* Input parameters *
* ==================== *
* @param game an object of Game different from the actual game *
* *
* Output parameters *
* ==================== *
* @returns a boolean, true if the games are the same and false if they ain't *
* *
*************************************************************************************************
*/
bool compareGame(const Game &game);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* Get the first player of the game. *
* *
* Input parameters *
* ==================== *
* (none) *
* *
* Output parameters *
* ==================== *
* @return The first player of the game. *
* *
*************************************************************************************************
*/
Player GetPlayerOne();
/**
*************************************************************************************************
* *
* Description *
* =========== *
* Get the second player of the game. *
* *
* Input parameters *
* ==================== *
* (none) *
* *
* Output parameters *
* ==================== *
* @return The second player of the game. *
* *
*************************************************************************************************
*/
Player GetPlayerTwo();
/**
*************************************************************************************************
* *
* Description *
* =========== *
* Get the reserve of cards for the game. *
* *
* Input parameters *
* ==================== *
* (none) *
* *
* Output parameters *
* ==================== *
* @return A vector of Card objects representing the reserve of cards for the game. *
* *
*************************************************************************************************
*/
vector<Card> getReserve();
/**
*************************************************************************************************
* *
* Description *
* =========== *
* Get the size of the game's reserve *
* *
* Input parameters *
* ==================== *
* no input parameters *
* *
* Output parameters *
* ==================== *
* @return an int representing the reserve's size *
* *
*************************************************************************************************
*/
int getSizeReserve();
};
/**
*************************************************************************************************
* *
* Description : *
* ============ *
* This function takes a vector of cards and a sorting criteria, and returns a vector of ranks *
* corresponding to the sorted order of the cards. *
* The rank of a card is its position in the original unsorted vector of cards. *
* *
* Input parameters *
* ==================== *
* @param reserve The vector of cards to be sorted and ranked *
* @param sortCriteria The sorting criteria to be used. This is a function that takes two Card *
* objects and returns a boolean indicating which one should come first in the sorted vector. *
* *
* Output parameters *
* ==================== *
* @return A vector of integers representing the ranks of the cards in the sorted order. *
* *
*************************************************************************************************
*/
vector<int> vectorOfRanks(const vector<Card> &reserve, Tri sortCriteria);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* the function applies a merge sort to the vector @param deck *
* *
* Input parameters *
* ==================== *
* @param deck -> a reference to the vector of integers that will be sorted *
* @param start1 -> an integer representing the start index of the first half of the vector *
* @param end1 -> an integer representing the end index of the first half of the vector *
* @param end2 -> an integer representing the end index of the second half of the vector *
* @param sortcriteria -> a Tri type value representing the sorting criterion *
* @param reserve -> a constant reference to a vector of Card objects called *
* *
* Output parameters *
* ==================== *
* returns nothing *
* *
*************************************************************************************************
*/
void mergeCard(vector<int> &deck, int start1, int end1, int end2, Tri sortcriteria, const vector<Card> &reserve);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* recursive implementation of mergeCard() *
* *
* Input parameters *
* ==================== *
* @param deck -> a reference to the vector of integers that will be sorted *
* @param start -> an integer representing the start index of the first half of the vector *
* @param end -> an integer representing the end index of the first half of the vector *
* @param sortcriteria -> a Tri type value representing the sorting criterion *
* @param reserve -> a constant reference to a vector of Card objects called *
* *
* Output parameters *
* ==================== *
* returns nothing *
* *
*************************************************************************************************
*/
void mergeSortBisCard(vector<int> &deck, int start, int end, Tri sortcriteria, const vector<Card> &reserve);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* this wrapper function provides a simpler interface for calling the "mergeSortBisCard" *
* function and starting the process of sorting the input vector. *
* *
* Input parameters *
* ==================== *
* @param deck -> a reference to the vector of integers that will be sorted *
* @param length -> an integer representing the length of the vector (length) *
* @param sortcriteria -> a Tri type value representing the sorting criterion *
* @param reserve -> a constant reference to a vector of Card objects called *
* *
* Output parameters *
* ==================== *
* returns nothing *
* *
*************************************************************************************************
*/
void mergeSortCard(vector<int> &deck, int length, Tri sortCriteria, const vector<Card> &reserve);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* sorts a vector of integers using the merge sort algorithm, with the ability to specify a *
* sorting criterion using a Tri type value and a reference to a vector of Card objects. *
* *
* Input parameters *
* ==================== *
* @param deck -> a reference to the vector of integers that will be sorted *
* @param sortcriteria -> a Tri type value representing the sorting criterion *
* @param reserve -> a constant reference to a vector of Card objects called *
* *
* Output parameters *
* ==================== *
* returns nothing *
* *
*************************************************************************************************
*/
void sortVectorOfCard(vector<int> &deck, Tri sortCriteria, const vector<Card> &reserve);
/**
*************************************************************************************************
* *
* Description *
* =========== *
* sorts the reserve of the targeted game in alphabetic order *
* *
* Input parameters *
* ==================== *
* @param reserve -> the vector of Card we want to sort *
* *
* Output parameters *
* ==================== *
* returns nothing *
* *
*************************************************************************************************
*/
void sortReserve(vector<Card> &reserve);
#endif //PROJECT_CARD_GAME_GAME_H
/*
⢀⡴⠑⡄⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣤⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠸⡇⠀⠿⡀⠀⠀⠀⣀⡴⢿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠑⢄⣠⠾⠁⣀⣄⡈⠙⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡀⠁⠀⠀⠈⠙⠛⠂⠈⣿⣿⣿⣿⣿⠿⡿⢿⣆⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢀⡾⣁⣀⠀⠴⠂⠙⣗⡀⠀⢻⣿⣿⠭⢤⣴⣦⣤⣹⠀⠀⠀⢀⢴⣶⣆
⠀⠀⢀⣾⣿⣿⣿⣷⣮⣽⣾⣿⣥⣴⣿⣿⡿⢂⠔⢚⡿⢿⣿⣦⣴⣾⠁⠸⣼⡿
⠀⢀⡞⠁⠙⠻⠿⠟⠉⠀⠛⢹⣿⣿⣿⣿⣿⣌⢤⣼⣿⣾⣿⡟⠉⠀⠀⠀⠀⠀
⠀⣾⣷⣶⠇⠀⠀⣤⣄⣀⡀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
⠀⠉⠈⠉⠀⠀⢦⡈⢻⣿⣿⣿⣶⣶⣶⣶⣤⣽⡹⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠉⠲⣽⡻⢿⣿⣿⣿⣿⣿⣿⣷⣜⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣷⣶⣮⣭⣽⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣀⣀⣈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠻⠿⠿⠿⠿⠛⠉
*/