forked from iwanhae/FakeCoin_Algorithm_Term_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgambling.cpp
143 lines (141 loc) · 4.97 KB
/
gambling.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
#include "common.h"
// int printFlag = 0;
int gambling(knownSet result) {
vector<int> tmp;
int estimatePvalue = ((double)result.fake.size() / (double)(result.fake.size() + result.real.size())) * 100;
tmp.clear();
if (result.unknown.size() == 1) {
if(printFlag) cout << "1gamble start" << endl;
if (estimatePvalue <= 50) {
int r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
if (printFlag) cout << "1 gamble SUC" << endl;
return SUCCESS;
}
else {
result.fake.push_back(result.unknown.at(0));
result.unknown.clear();
r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
return SUCCESS;
}
else {
cout << "\tFAIL";
return ERROR;
}
}
}
else {
result.fake.push_back(result.unknown.at(0));
int r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
if (printFlag) cout << "1 gamble SUC" << endl;
return SUCCESS;
}
else {
result.fake.pop_back();
result.real.push_back(result.unknown.at(0));
result.unknown.clear();
r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
return SUCCESS;
}
else {
if (printFlag) cout << "\tFAIL";
return ERROR;
}
}
}
}
else {
if (printFlag) cout << "2gamble start" << endl;
if (estimatePvalue <= 50) {
int r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
if (printFlag) cout << "2 gamble SUC" << endl;
return SUCCESS;
}
else {
vector<int> tmpa;
vector<int> tmpb;
tmpa.push_back(result.unknown.at(0));
tmpb.push_back(result.unknown.at(1));
r = balanceWithVector(tmpa, tmpb);
switch (r) {
case LARGE: {
result.real.push_back(result.unknown.at(0));
result.fake.push_back(result.unknown.at(1));
result.unknown.clear();
break;
}
case EQUAL: {
result.fake.push_back(result.unknown.at(0));
result.fake.push_back(result.unknown.at(1));
result.unknown.clear();
break;
}
case SMALL: {
result.fake.push_back(result.unknown.at(0));
result.real.push_back(result.unknown.at(1));
result.unknown.clear();
break;
}
}
r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
return SUCCESS;
}
else {
if (printFlag) cout << "\tFAIL";
return ERROR;
}
}
}
else {
result.fake.push_back(result.unknown.at(0));
result.fake.push_back(result.unknown.at(1));
int r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
if (printFlag) cout << "2 gamble SUC" << endl;
return SUCCESS;
}
else {
result.fake.pop_back();
result.fake.pop_back();
vector<int> tmpa;
vector<int> tmpb;
tmpa.push_back(result.unknown.at(0));
tmpb.push_back(result.unknown.at(1));
r = balanceWithVector(tmpa, tmpb);
switch (r) {
case LARGE: {
result.real.push_back(result.unknown.at(0));
result.fake.push_back(result.unknown.at(1));
result.unknown.clear();
break;
}
case EQUAL: {
result.real.push_back(result.unknown.at(0));
result.real.push_back(result.unknown.at(1));
result.unknown.clear();
break;
}
case SMALL: {
result.fake.push_back(result.unknown.at(0));
result.real.push_back(result.unknown.at(1));
result.unknown.clear();
break;
}
}
r = balanceWithVector(result.fake, tmp);
if (r == SUCCESS) {
return SUCCESS;
}
else {
if (printFlag) cout << "\tFAIL";
return ERROR;
}
}
}
}
}