-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.h
263 lines (215 loc) · 7.88 KB
/
constants.h
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
#ifndef CONSTANTS_H
#define CONSTANTS_H
// #define CONTAINER
#define LOCAL_RUNNER
/*
#include <QString>
#include <QVector>
#include <QDebug>
#include <qmath.h>
#include <QTime>
#include <qglobal.h>
#include <QProcessEnvironment>
#include <random>
#include <QSettings>
#include <QJsonObject>
*/
#include <random>
#include <string>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>
#define QPair std::pair
#define QSet std::set
#define QMap std::map
#define qSqrt sqrt
#define qCeil(X)((int)ceil(X))
#define qAbs abs
#define qSin sin
#define qCos cos
#define qAsin sin
#define qAcos cos
#define qAtan2 atan2
#define qAtan atan
#define qMax std::max
#define qMin std::min
#define protected public
#define private public
/*
#define qCos cos
#define qSin sin
#define qSqrt sqrt
#define qAbs fabs
*/
typedef unsigned long long int quint64;
typedef std::string QString ;
// yes ugly
#define DEFINE_QSETTINGS(VARIABLE_NAME) QSettings VARIABLE_NAME("LocalRunner.ini", QSettings::IniFormat)
struct Constants{
public:
// name // default
int GAME_TICKS=7500; // 75000 ticks
int GAME_WIDTH=660; // 660
int GAME_HEIGHT=660; // 660
int SUM_RESP_TIMEOUT=500; // 500 secs
int RESP_TIMEOUT; // 5 sec
int TICK_MS=16; // 16 ms
int BASE_TICK=50; // every 50 ticks
std::string SEED; // from std::random_device
double INERTION_FACTOR=10; // 10.0
double VISCOSITY=0.25; // 0.25
double SPEED_FACTOR; // 25.0
double FOOD_MASS=1; // 1.0
double VIRUS_RADIUS=22; // 22.0
double VIRUS_SPLIT_MASS=80; // 80.0
int MAX_FRAGS_CNT=10; // 10
int TICKS_TIL_FUSION=250; // 250 ticks
static Constants &instance() {
static Constants ins;
return ins;
}
static std::string generate_seed(uint length = 10) {
std::random_device dev;
const std::string alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
std::uniform_int_distribution<> dist(0, static_cast<int>(alphabet.length() - 1));
std::string seed;
while (seed.length() < length) {
seed += alphabet[static_cast<uint>(dist(dev))];
}
return seed;
}
#if(0)
static Constants &initialize(const QProcessEnvironment &env) {
Constants& c = instance();
DEFINE_QSETTINGS(settings);
settings.beginGroup("constants");
#define SET_CONSTANT(NAME, DEFAULT, CONVERT) do { \
c.NAME = getSettingValue(#NAME, env, settings, DEFAULT).CONVERT(); \
} while(false)
SET_CONSTANT(GAME_TICKS, "75000", toInt);
#if defined LOCAL_RUNNER
SET_CONSTANT(GAME_WIDTH, "660", toInt);
SET_CONSTANT(GAME_HEIGHT, "660", toInt);
SET_CONSTANT(SUM_RESP_TIMEOUT, "500", toInt);
#elif defined SERVER_RUNNER
SET_CONSTANT(GAME_WIDTH, "990", toInt);
SET_CONSTANT(GAME_HEIGHT, "990", toInt);
SET_CONSTANT(SUM_RESP_TIMEOUT, "150", toInt);
#endif
SET_CONSTANT(TICK_MS, "16", toInt);
SET_CONSTANT(BASE_TICK, "50", toInt);
SET_CONSTANT(INERTION_FACTOR, "10.0", toDouble);
SET_CONSTANT(VISCOSITY, "0.25", toDouble);
SET_CONSTANT(SPEED_FACTOR, "25.0", toDouble);
SET_CONSTANT(FOOD_MASS, "1.0", toDouble);
SET_CONSTANT(VIRUS_RADIUS, "22.0", toDouble);
SET_CONSTANT(VIRUS_SPLIT_MASS, "80.0", toDouble);
SET_CONSTANT(MAX_FRAGS_CNT, "10", toInt);
SET_CONSTANT(TICKS_TIL_FUSION, "250", toInt);
SET_CONSTANT(RESP_TIMEOUT, "5", toInt);
#undef SET_CONSTANT
settings.endGroup();
settings.sync();
c.SEED = env.value("SEED", "").toStdString();
return c;
}
QJsonObject toJson() const {
return {
{"GAME_WIDTH", GAME_WIDTH},
{"GAME_HEIGHT", GAME_HEIGHT},
{"GAME_TICKS", GAME_TICKS},
{"FOOD_MASS", FOOD_MASS},
{"MAX_FRAGS_CNT", MAX_FRAGS_CNT},
{"TICKS_TIL_FUSION", TICKS_TIL_FUSION},
{"VIRUS_RADIUS", VIRUS_RADIUS},
{"VIRUS_SPLIT_MASS", VIRUS_SPLIT_MASS},
{"VISCOSITY", VISCOSITY},
{"INERTION_FACTOR", INERTION_FACTOR},
{"SPEED_FACTOR", SPEED_FACTOR},
};
}
private:
static QString getSettingValue(const QString& name,
const QProcessEnvironment& env,
QSettings& section,
const QString& defaultValue)
{
if (!section.contains(name)) {
section.setValue(name, defaultValue);
}
return env.value(name, section.value(name).toString());
}
#endif
};
const QString LOG_DIR = "/var/tmp/";
const QString LOG_FILE = "visio_{1}.log";
const QString DEBUG_FILE = "{1}.log";
const QString DUMP_FILE = "{1}_dump.log";
const QString SCORES_FILE = "scores.json";
const QString MAIN_JSON_KEY = "visio";
const QString DEBUG_JSON_KEY = "debug";
const QString SCORES_JSON_KEY = "scores";
const int START_FOOD_SETS = 4;
const int ADD_FOOD_SETS = 2;
const int ADD_FOOD_DELAY = 40;
const double FOOD_RADIUS = 2.5;
//const double FOOD_MASS = 1.0;
const int START_VIRUS_SETS = 1;
const int ADD_VIRUS_SETS = 1;
const int ADD_VIRUS_DELAY = 1200;
//const double VIRUS_RADIUS = 22.0;
const double VIRUS_MASS = 40.0;
const int START_PLAYER_SETS = 1;
const int START_PLAYER_OFFSET = 400;
const double PLAYER_RADIUS_FACTOR = 2;
const double PLAYER_MASS = 40.0;
const double PLAYER_RADIUS = PLAYER_RADIUS_FACTOR * std::sqrt(PLAYER_MASS);
const double VIS_FACTOR = 4.0; // vision = radius * VF
const double VIS_FACTOR_FR = 2.5; // vision = radius * VFF * qSqrt(fragments.count())
const double VIS_SHIFT = 10.0; // dx = qCos(angle) * VS; dy = qSin(angle) * VS
const double DRAW_SPEED_FACTOR = 14.0;
const double COLLISION_POWER = 20.;
const double MASS_EAT_FACTOR = 1.20; // mass > food.mass * MEF
const double DIAM_EAT_FACTOR = 2./3.; // dist - eject->getR() + (eject->getR() * 2) * DIAM_EAT_FACTOR < radius
const double RAD_HURT_FACTOR = 2./3.; // (radius * RHF + player.radius) > dist
const double MIN_BURST_MASS = 60.0; // MBM * 2 < mass
//const int MAX_FRAGS_CNT = 10;
const double BURST_START_SPEED = 8.0;
const double BURST_ANGLE_SPECTRUM = M_PI; // angle - BAM / 2 + I*BAM / frags_cnt
//const double PLAYER_VISCOSITY = 0.25;
//const int TICKS_TIL_FUSION = 250;
const double MIN_SPLIT_MASS = 120.0; // MSM < mass
const double SPLIT_START_SPEED = 9.0;
const double MIN_EJECT_MASS = 40.0;
const double EJECT_START_SPEED = 8.0;
const double EJECT_RADIUS = 4.0;
const double EJECT_MASS = 15.0;
//const double EJECT_VISCOSITY = 0.25;
//const double VIRUS_VISCOSITY = 0.25;
const double VIRUS_SPLIT_SPEED = 8.0;
//const double VIRUS_SPLIT_MASS = 80.0;
const double MIN_SHRINK_MASS = 100;
const double SHRINK_FACTOR = 0.01; // (-1) * (mass - MSM) * SF
const int SHRINK_EVERY_TICK = 50;
const double BURST_BONUS = 5.0; // mass += BB
const int SCORE_FOR_FOOD = 1;
const int SCORE_FOR_PLAYER = 10;
const int SCORE_FOR_LAST = 100;
const int SCORE_FOR_BURST = 2;
// TCP Server
const QString HOST = "0.0.0.0";
const int PORT = 8000;
const int MAX_RESP_LEN = 3000;
const int MAX_DEBUG_LEN = 1000;
const int MAX_ID_LEN = 100;
const int CONNECT_TIMEOUT = 200; // seconds
//const int RESP_TIMEOUT = 5; // seconds
//const int SUM_RESP_TIMEOUT = 150; // seconds
const int PRE_PAUSE = 20; // seconds
const QString CONNECT_EXPIRED = "Ожидание соединения превышено!";
const QString RESP_EXPIRED = "Ожидание ответа превышено!";
const QString SUM_RESP_EXPIRED = "Суммарное ожидание клиента превышено. Клиент будет отключён!";
const QString CLIENT_DISCONNECTED = "Решение отключилось от механики до окончания!";
const int MAX_GAME_FOOD = 2000;
const int MAX_GAME_VIRUS = 20;
#endif // CONSTANTS_H