forked from dsuchka/tyrant_optimize_closed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tyrant.h
428 lines (380 loc) · 9.44 KB
/
tyrant.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#ifndef TYRANT_H_INCLUDED
#define TYRANT_H_INCLUDED
#define TYRANT_OPTIMIZER_VERSION "2.54.3"
#include <string>
#include <sstream>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <boost/algorithm/string.hpp>
class Card;
enum Faction
{
allfactions,
imperial,
raider,
bloodthirsty,
xeno,
righteous,
progenitor,
num_factions
};
extern const std::string faction_names[num_factions];
namespace Skill {
enum Skill
{
// Placeholder for no-skill:
no_skill,
// Activation (harmful):
enfeeble, jam, mortar, siege, strike, sunder, weaken,
// Activation (helpful):
enhance, evolve, heal, mend, overload, protect, rally,
enrage, entrap, rush,
// Activation (unclassified/polymorphic):
mimic,
// Defensive:
armor, avenge, corrosive, counter, evade, subdue,
payback, revenge, tribute, refresh, wall, barrier,
// Combat-Modifier:
coalition, legion, pierce, rupture, swipe, drain, venom,
// Damage-Dependent:
berserk, inhibit, sabotage, leech, poison,
// Triggered:
allegiance, flurry, valor, stasis, summon,
// End of skills
num_skills
};
enum Trigger
{
activate,
play,
//APN
attacked,
death,
num_triggers
};
}
extern const std::string skill_names[Skill::num_skills];
extern const std::string skill_trigger_names[Skill::num_triggers];
namespace PassiveBGE {
enum PassiveBGE
{
// Placeholder for no-bge:
no_bge,
// Passive BGEs
bloodlust, brigade, counterflux, divert, enduringrage, fortification, heroism,
zealotspreservation, metamorphosis, megamorphosis, revenge, turningtides, virulence,
haltedorders, devour, criticalreach, temporalbacklash, furiosity, oath_of_loyalty,
bloodvengeance, coldsleep,
// End of BGEs
num_passive_bges
};
}
extern const std::string passive_bge_names[PassiveBGE::num_passive_bges];
inline bool is_activation_harmful_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::enfeeble:
case Skill::jam:
case Skill::mortar:
case Skill::siege:
case Skill::strike:
case Skill::sunder:
case Skill::weaken:
return true;
default:
return false;
}
}
inline bool is_activation_hostile_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::mimic:
return true;
default:
return is_activation_harmful_skill(skill_id);
}
}
inline bool is_activation_helpful_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::enhance:
case Skill::evolve:
case Skill::heal:
case Skill::mend:
case Skill::overload:
case Skill::protect:
case Skill::rally:
case Skill::enrage:
case Skill::entrap:
case Skill::rush:
return true;
default:
return false;
}
}
inline bool is_activation_allied_skill(Skill::Skill skill_id)
{
return is_activation_helpful_skill(skill_id);
}
inline bool is_activation_skill(Skill::Skill skill_id)
{
return is_activation_hostile_skill(skill_id)
|| is_activation_allied_skill(skill_id)
;
}
inline bool is_activation_skill_with_x(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::enfeeble:
case Skill::mortar:
case Skill::siege:
case Skill::strike:
case Skill::sunder:
case Skill::weaken:
case Skill::enhance:
case Skill::mimic:
case Skill::heal:
case Skill::mend:
case Skill::protect:
case Skill::rally:
case Skill::enrage:
case Skill::entrap:
case Skill::rush:
return true;
default:
return false;
}
}
inline bool is_defensive_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::armor:
case Skill::avenge:
case Skill::corrosive:
case Skill::counter:
case Skill::evade:
case Skill::subdue:
case Skill::payback:
case Skill::revenge:
case Skill::tribute:
case Skill::refresh:
case Skill::wall:
return true;
default:
return false;
}
}
inline bool is_combat_modifier_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::legion:
case Skill::pierce:
case Skill::rupture:
case Skill::swipe:
case Skill::drain:
case Skill::venom:
return true;
default:
return false;
}
}
inline bool is_damage_dependent_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::berserk:
case Skill::inhibit:
case Skill::sabotage:
case Skill::leech:
case Skill::poison:
return true;
default:
return false;
}
}
inline bool is_triggered_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::allegiance:
case Skill::flurry:
case Skill::valor:
case Skill::stasis:
case Skill::summon:
return true;
default:
return false;
}
}
inline PassiveBGE::PassiveBGE passive_bge_name_to_id(const std::string& name_)
{
std::string name(name_);
name.erase(std::remove_if(name.begin(), name.end(), boost::is_any_of("-")), name.end());
for (unsigned i(PassiveBGE::no_bge); i < PassiveBGE::num_passive_bges; ++i)
{
if (boost::iequals(passive_bge_names[i], name))
{
return static_cast<PassiveBGE::PassiveBGE>(i);
}
}
return PassiveBGE::no_bge;
}
inline void map_keys_to_set(const std::unordered_map<unsigned, unsigned>& m, std::unordered_set<unsigned>& s)
{
for (auto it = m.begin(); it != m.end(); ++it)
{
s.insert(it->first);
}
}
inline unsigned safe_minus(unsigned x, unsigned y)
{
return (x > y) ? (x - y) : 0;
}
namespace CardType {
enum CardType {
commander,
assault,
structure,
num_cardtypes
};
}
namespace CardCategory {
enum CardCategory {
normal,
special,
fortress_defense,
fortress_siege,
fortress_conquest,
dominion_alpha,
dominion_material,
num_cardcategories
};
}
extern const std::string cardtype_names[CardType::num_cardtypes];
extern const std::string rarity_names[];
extern unsigned const upgrade_cost[];
extern std::map<const Card*, unsigned> dominion_cost[3][7];
extern std::map<const Card*, unsigned> dominion_refund[3][7];
namespace DeckType {
enum DeckType {
deck,
mission,
raid,
campaign,
custom_deck,
num_decktypes
};
}
extern std::string decktype_names[DeckType::num_decktypes];
enum gamemode_t
{
fight,
surge,
};
#ifndef NQUEST
namespace QuestType
{
enum QuestType
{
none,
skill_use,
skill_damage,
faction_assault_card_use,
type_card_use,
faction_assault_card_kill,
type_card_kill,
card_survival,
num_objective_types
};
}
#endif
enum class OptimizationMode
{
notset,
winrate,
defense,
war,
brawl,
brawl_defense,
raid,
campaign,
#ifndef NQUEST
quest,
#endif
num_optimization_mode
};
extern unsigned min_possible_score[(size_t)OptimizationMode::num_optimization_mode];
extern unsigned max_possible_score[(size_t)OptimizationMode::num_optimization_mode];
template <typename x_type>
struct _SkillSpec
{
Skill::Skill id;
x_type x;
Faction y;
unsigned n;
unsigned c;
Skill::Skill s;
Skill::Skill s2;
bool all;
unsigned card_id;
};
using SkillSpec = _SkillSpec<unsigned>;
using SkillSpecXMult = _SkillSpec<double>;
// --------------------------------------------------------------------------------
// Common functions
template<typename T>
std::string to_string(const T val)
{
std::stringstream s;
s << val;
return s.str();
}
inline uint8_t byte_bits_count(register uint8_t i)
{
i = i - ((i >> 1) & 0x55);
i = (i & 0x33) + ((i >> 2) & 0x33);
return (i + (i >> 4)) & 0x0F;
}
//---------------------- Debugging stuff ---------------------------------------
extern signed debug_print;
extern unsigned debug_cached;
extern bool debug_line;
extern std::string debug_str;
#ifndef NDEBUG
#define _DEBUG_MSG(v, format, args...) \
{ \
if(__builtin_expect(debug_print >= v, false)) \
{ \
if(debug_line) { printf("%i - " format, __LINE__ , ##args); } \
else if(debug_cached) { \
char buf[4096]; \
snprintf(buf, sizeof(buf), format, ##args); \
debug_str += buf; \
} \
else { printf(format, ##args); } \
std::cout << std::flush; \
} \
}
#define _DEBUG_SELECTION(format, args...) \
{ \
if(__builtin_expect(debug_print >= 2, 0)) \
{ \
_DEBUG_MSG(2, "Possible targets of " format ":\n", ##args); \
fd->print_selection_array(); \
} \
}
#define _DEBUG_ASSERT(expr) { assert(expr); }
#else
#define _DEBUG_MSG(v, format, args...)
#define _DEBUG_SELECTION(format, args...)
#define _DEBUG_ASSERT(expr)
#endif
#endif