-
Notifications
You must be signed in to change notification settings - Fork 39
/
game.cpp
227 lines (190 loc) · 5.84 KB
/
game.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
//
// game.cpp
// DouDiZhu
//
// Created by Neil on 07/07/2017.
// Copyright © 2017 Neil. All rights reserved.
//
#include "game.hpp"
#include <random>
/*
*/
int LandScore(GameSituation &clsGameSituation, HandCardData &clsHandCardData, int &sum_value)
{
clsHandCardData.uctHandCardValue=get_HandCardValue(clsHandCardData);
sum_value = clsHandCardData.uctHandCardValue.SumValue;
// cout << "SumValue is :" << sum_value << ",";
// cout << "NeedRound is :" << clsHandCardData.uctHandCardValue.NeedRound << endl;
// if (SumValue<10)
// {
// return 0;
// }
// else
if (sum_value < 15)
{
return 1;
}
else if (sum_value < 20)
{
return 2;
}
else
{
return 3;
}
}
//
void InitCards2(const py::array_t<int> &pycards, vector<int> &cards)
{
auto init_cards = pycards.unchecked<1>();
cards.clear();
vector <int> tmpCards;
int i;
for (int i = 0; i < init_cards.shape(0); ++i) {
tmpCards.push_back(init_cards[i]);
}
//
for (i = tmpCards.size(); i>0; i--) {
srand(unsigned(time(NULL)));
//
int index = rand() % i;
cards.push_back(tmpCards[index]);
tmpCards.erase(tmpCards.begin() + index);
}
}
void InitCards(vector <int> &Cards, std::mt19937& g)
{
//Cards
// Cards.clear();
//
// vector <int> tmpCards;
// int i;
//
// //5652535455
for (int i = 0; i < 53; i++) {
Cards.push_back(i);
}
Cards.push_back(56);
std::shuffle(Cards.begin(), Cards.end(), g);
//
//
// //
// for (i = tmpCards.size(); i>0; i--) {
//
// //
// int index = rand() % i;
// Cards.push_back(tmpCards[index]);
// tmpCards.erase(tmpCards.begin() + index);
// }
}
//
void InitCards_Appoint(vector <int> &Cards)
{
//Cards
Cards.clear();
/*********************/
Cards.push_back(48); Cards.push_back(50); Cards.push_back(49);
Cards.push_back(44); Cards.push_back(47); Cards.push_back(35);
Cards.push_back(40); Cards.push_back(46); Cards.push_back(34);
Cards.push_back(36); Cards.push_back(45); Cards.push_back(33);
Cards.push_back(23); Cards.push_back(43); Cards.push_back(31);
Cards.push_back(22); Cards.push_back(42); Cards.push_back(30);
Cards.push_back(21); Cards.push_back(41); Cards.push_back(29);
Cards.push_back(19); Cards.push_back(39); Cards.push_back(27);
Cards.push_back(18); Cards.push_back(38); Cards.push_back(26);
Cards.push_back(17); Cards.push_back(37); Cards.push_back(25);
Cards.push_back(15); Cards.push_back(32); Cards.push_back(20);
Cards.push_back(14); Cards.push_back(28); Cards.push_back(16);
Cards.push_back(13); Cards.push_back(24); Cards.push_back(12);
Cards.push_back(11); Cards.push_back(3); Cards.push_back(7);
Cards.push_back(10); Cards.push_back(2); Cards.push_back(6);
Cards.push_back(9); Cards.push_back(1); Cards.push_back(5);
Cards.push_back(8); Cards.push_back(0); Cards.push_back(4);
Cards.push_back(51); Cards.push_back(52); Cards.push_back(56);
}
//
void SendCards(GameSituation & clsGameSituation, ALLCardsList &uctALLCardsList, std::mt19937& g)
{
//
vector <int> Cards;
InitCards(Cards, g);
//InitCards_Appoint(Cards);
int i, j, k;
j = 0;
for (i = 0; i < 3; i++) {
for (k = 0; k < 17; k++,j++) {
uctALLCardsList.arrCardsList[i].push_back(Cards[j]);
}
}
//
clsGameSituation.DiPai[0] = Cards[j];
clsGameSituation.DiPai[1] = Cards[j+1];
clsGameSituation.DiPai[2] = Cards[j+2];
return;
}
void SendCards_manual(const py::array_t<int>& pycards, GameSituation & clsGameSituation, ALLCardsList &uctALLCardsList, std::mt19937& g)
{
auto init_cards = pycards.unchecked<1>();
vector<int> cards;
int i;
for (int i = 0; i < init_cards.shape(0); ++i) {
cards.push_back(init_cards[i]);
}
std::shuffle(cards.begin(), cards.end(), g);
int j, k;
j = 0;
for (i = 0; i < 3; i++) {
for (k = 0; k < cards.size() / 3 - 1; k++, j++) {
uctALLCardsList.arrCardsList[i].push_back(cards[j]);
// std::cout << cards[j] << " ";
}
}
// std::cout << std::endl;
clsGameSituation.DiPai[0] = cards[j];
clsGameSituation.DiPai[1] = cards[j+1];
clsGameSituation.DiPai[2] = cards[j+2];
return;
}
void SendCards2_manual(const py::array_t<int>& pycards, GameSituation & clsGameSituation, ALLCardsList &uctALLCardsList) {
auto init_cards = pycards.unchecked<1>();
vector<int> cards;
int i;
for (int i = 0; i < init_cards.shape(0); ++i) {
cards.push_back(init_cards[i]);
// std::cout << init_cards[i] << " ";
}
// std::cout << std::endl;
int j, k;
j = 0;
for (i = 0; i < 2; i++) {
for (k = 0; k < cards.size() / 2; k++, j++) {
uctALLCardsList.arrCardsList[i].push_back(cards[j]);
}
}
return;
}
void SendCards2(const py::array_t<int>& init_cards, GameSituation & clsGameSituation, ALLCardsList &uctALLCardsList) {
vector<int> cards;
int i, j, k;
j = 0;
for (k = 0; k < cards.size() / 2; k++) {
for (i = 0; i < 2; i++,j++)
{
uctALLCardsList.arrCardsList[i].push_back(cards[j]);
}
}
HandCardData data1, data2;
data1.color_nHandCardList = uctALLCardsList.arrCardsList[0];
data2.color_nHandCardList = uctALLCardsList.arrCardsList[1];
data1.Init();
data2.Init();
auto value1 = get_HandCardValue(data1);
auto value2 = get_HandCardValue(data2);
// 找一个相对比较好的局
if (value1.SumValue < value2.SumValue + 5) {
uctALLCardsList.arrCardsList[0].clear();
uctALLCardsList.arrCardsList[1].clear();
return SendCards2(init_cards, clsGameSituation, uctALLCardsList);
}
return;
}