-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitial.cpp
65 lines (52 loc) · 1.12 KB
/
Initial.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
#include <string>
#include <vector>
#include <ctime>
#include <algorithm>
#include <cstdlib>
#include "struct.h"
#define SUITS 4
#define FACES 13
#define CARDS 52
void _ShuffleVector(std::vector<int> &VectorIndex) //khoi tao va tron vector
{
VectorIndex.clear();
for (int i = 1; i <= 52; i++)
VectorIndex.push_back(i);
std::random_shuffle(VectorIndex.begin(), VectorIndex.end());
//ham tron cac phan tu cua vector
}
void ShuffleCards(int Deck[][FACES]) //tron nguyen bo bai
{
std::vector<int> VectorIndex;
_ShuffleVector(VectorIndex);
for (int i = 0; i < SUITS; i++)
for (int j = 0; j < FACES; j++)
{
Deck[i][j] = VectorIndex.back();
VectorIndex.pop_back();
}
}
void DealCards(Cards DeckShuffled[])
{
int Deck[SUITS][FACES] = { 0 };
ShuffleCards(Deck);
int RightOrder = 1;
do
{
bool Found = false;
for (int i = 0; i < SUITS; i++)
{
for (int j = 0; j < FACES; j++)
if (Deck[i][j] == RightOrder)
{
DeckShuffled[RightOrder - 1].Suits = i;
DeckShuffled[RightOrder - 1].Faces = j;
Found = true;
RightOrder++;
break;
}
if (Found)
break;
}
} while (RightOrder <= CARDS);
}