-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cc
161 lines (132 loc) · 3.71 KB
/
utils.cc
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
#include "utils.h"
#include <algorithm>
#include <random>
namespace bridge_learning_env {
template <>
int ParameterValue<int>(const GameParameters& params, const std::string& key,
int default_value) {
auto iter = params.find(key);
if (iter == params.end()) {
return default_value;
}
return std::stoi(iter->second);
}
template <>
std::string ParameterValue<std::string>(const GameParameters& params,
const std::string& key,
std::string default_value) {
auto iter = params.find(key);
if (iter == params.end()) {
return default_value;
}
return iter->second;
}
template <>
double ParameterValue<double>(const GameParameters& params,
const std::string& key, double default_value) {
auto iter = params.find(key);
if (iter == params.end()) {
return default_value;
}
return std::stod(iter->second);
}
template <>
bool ParameterValue<bool>(const GameParameters& params, const std::string& key,
bool default_value) {
auto iter = params.find(key);
if (iter == params.end()) {
return default_value;
}
return iter->second == "1" || iter->second == "true" ||
iter->second == "True";
}
std::string GameParametersToString(const GameParameters& params) {
std::string str{};
if (params.empty()) {
return "";
}
if (params.count("name")) {
str = params.at("name");
}
str.push_back('(');
bool first = true;
for (const auto& [key, value] : params) {
if (key != "name") {
if (!first)
str.push_back(',');
str.append(key);
str.append("=");
str.append(value);
first = false;
}
}
str.push_back(')');
return str;
}
std::vector<int> Arange(int start, int end) {
std::vector<int> rv(end - start);
for (int i = start; i < end; ++i) {
rv[i - start] = i;
}
return rv;
}
std::vector<int> Permutation(int num) {
std::random_device rd;
std::mt19937 rng(rd());
return Permutation(num, rng);
}
std::vector<int> Permutation(int num, std::mt19937& rng) {
std::vector<int> ret = Arange(0, num);
std::shuffle(ret.begin(), ret.end(), rng);
return ret;
}
std::vector<std::string> StrSplit(const std::string& str, char delimiter) {
std::vector<std::string> result;
std::stringstream ss(str);
std::string token;
while (std::getline(ss, token, delimiter)) {
result.push_back(token);
}
return result;
}
void SimpleDDSFunctions() {
// SetMaxThreads(0);
// SetThreading(0);
// SetResources(100, 16);
// FreeMemory();
// DDSInfo info;
// GetDDSInfo(&info);
// char line[80];
// ErrorMessage(-1, line);
// dealPBN dl;
// futureTricks fut;
// SolveBoardPBN(dl, -1, 1, 2, &fut, 0);
// deal dl2;
// SolveBoard(dl2, -1, 1, 2, &fut, 0);
// ddTableDeal table_dl;
// ddTableResults table_res;
// CalcDDtable(table_dl, &table_res);
// ddTableDealPBN tableDealPBN;
// ddTableResults tablep;
// CalcDDtablePBN(tableDealPBN, &tablep);
// ddTableDeals deals;
// int trumpFilter[DDS_STRAINS] = {1, 1, 1, 1, 1};
// ddTablesRes res;
// allParResults pres;
// CalcAllTables(&deals, 2, trumpFilter, &res, &pres);
// ddTableDealsPBN deals2;
// CalcAllTablesPBN(&deals2, 2, trumpFilter, &res, &pres);
// boardsPBN bop;
// solvedBoards solvedb;
// SolveAllBoards(&bop, &solvedb);
// boards bo;
// SolveAllBoardsBin(&bo, &solvedb);
// SolveAllChunks(&bop, &solvedb, 0);
// SolveAllChunksBin(&bo, &solvedb, 0);
// SolveAllChunksPBN(&bop, &solvedb, 0);
// parResults par;
// Par(&table_res, &par, 0);
// CalcPar(table_dl, 0, &table_res, &par);
// CalcParPBN(tableDealPBN, &table_res, 0, &par);
}
} // namespace bridge_learning_env