forked from andor9/tyrant_optimize
-
Notifications
You must be signed in to change notification settings - Fork 9
/
tyrant.h
489 lines (435 loc) · 10.8 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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#ifndef TYRANT_H_INCLUDED
#define TYRANT_H_INCLUDED
#ifndef TYRANT_OPTIMIZER_VERSION
#define TYRANT_OPTIMIZER_VERSION "NO VERSION"
#endif
#include <string>
#include <sstream>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <boost/algorithm/string.hpp>
enum Fix
{
no_fix,
enhance_early,
revenge_on_death,
death_from_bge,
legion_under_mega,
barrier_each_turn,
dont_evade_mimic_selection,
leech_increase_max_hp,
counter_without_damage,
subdue_before_attack,
corrosive_protect_armor,
poison_after_attacked,
num_fixes
};
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):
evolve, heal, mend, overload, protect, rally, fortify,
enrage, entrap, rush,
// Activation (unclassified/polymorphic):
mimic,
// Defensive:
armor, avenge, scavenge, corrosive, counter, evade, subdue, absorb, flying,
payback, revenge, tribute, refresh, wall, barrier,
// Combat-Modifier:
coalition, legion, pierce, rupture, swipe, drain, venom, hunt,mark,
// Damage-Dependent:
berserk, leech, poison,
// Instant-Debuff:
inhibit, sabotage, disease,
// Triggered:
allegiance, flurry, valor, stasis, summon, bravery, enhance,
// End of skills
num_skills
};
enum Trigger
{
activate,
play,
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,ironwill,unity,devotion,crackdown,superheroism,
// 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::fortify:
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::fortify:
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::scavenge:
case Skill::corrosive:
case Skill::counter:
case Skill::evade:
case Skill::subdue:
case Skill::absorb:
case Skill::flying:
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::coalition:
case Skill::legion:
case Skill::pierce:
case Skill::rupture:
case Skill::swipe:
case Skill::drain:
case Skill::venom:
case Skill::hunt:
case Skill::mark:
return true;
default:
return false;
}
}
inline bool is_instant_debuff_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::inhibit:
case Skill::sabotage:
case Skill::disease:
return true;
default:
return false;
}
}
inline bool is_damage_dependent_skill(Skill::Skill skill_id)
{
switch(skill_id)
{
case Skill::berserk:
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:
case Skill::bravery:
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 Faction faction_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()); //Mostly useless
for (unsigned i(allfactions); i < num_factions; ++i)
{
if (boost::iequals(faction_names[i], name))
{
return static_cast<Faction>(i);
}
}
return allfactions;
}
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 OptimizationMode
{
notset,
winrate,
defense,
war,
war_defense,
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
namespace tuo {
template<typename T>
std::string to_string(const T val)
{
std::stringstream s;
s << val;
return s.str();
}
}
inline uint8_t byte_bits_count(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_cached) { \
char buf[4096]; \
if(debug_line){ snprintf(buf, sizeof(buf), "%i - " format, __LINE__, ##args);} \
else { snprintf(buf, sizeof(buf), format, ##args); } \
debug_str += buf; \
} \
else { if(debug_line){ printf("%i - " format, __LINE__ , ##args);} \
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