-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathleech_utils.h
99 lines (82 loc) · 2.52 KB
/
leech_utils.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
#ifndef _LEECH_UTILS_H
#define _LEECH_UTILS_H
#include <algorithm>
#include <cstdio>
struct gem_O {
gem_O* father;
gem_O* mother;
int grade; //using short does NOT improve time/memory usage
double leech;
};
// --------------------
// Common gem interface
// --------------------
#include "gem_utils.h"
#include "gem_stats.h"
inline double gem_power(const gem_O& gem1) {
return gem1.leech;
}
inline void gem_print(const gem_O* p_gem) {
printf("Grade:\t%d\nLeech:\t%f\n\n", p_gem->grade, p_gem->leech);
}
inline char gem_color(const gem_O* p_gem) {
if (p_gem->leech==0) return COLOR_CHHIT;
else return COLOR_LEECH;
}
// -----------------
// Combining section
// -----------------
inline void gem_comb_eq(const gem_O *p_gem1, const gem_O *p_gem2, gem_O *p_gem_combined)
{
p_gem_combined->grade = p_gem1->grade+1;
if (p_gem1->leech > p_gem2->leech) p_gem_combined->leech = LEECH_EQ_1*p_gem1->leech + LEECH_EQ_2*p_gem2->leech;
else p_gem_combined->leech = LEECH_EQ_1*p_gem2->leech + LEECH_EQ_2*p_gem1->leech;
}
inline void gem_comb_d1(const gem_O *p_gem1, const gem_O *p_gem2, gem_O *p_gem_combined) //bigger is always gem1
{
p_gem_combined->grade = p_gem1->grade;
if (p_gem1->leech > p_gem2->leech) p_gem_combined->leech = LEECH_D1_1*p_gem1->leech + LEECH_D1_2*p_gem2->leech;
else p_gem_combined->leech = LEECH_D1_1*p_gem2->leech + LEECH_D1_2*p_gem1->leech;
}
inline void gem_comb_gn(const gem_O *p_gem1, const gem_O *p_gem2, gem_O *p_gem_combined)
{
p_gem_combined->grade = std::max(p_gem1->grade, p_gem2->grade);
if (p_gem1->leech > p_gem2->leech) p_gem_combined->leech = LEECH_GN_1*p_gem1->leech + LEECH_GN_2*p_gem2->leech;
else p_gem_combined->leech = LEECH_GN_1*p_gem2->leech + LEECH_GN_2*p_gem1->leech;
}
inline void gem_combine(gem_O *p_gem1, gem_O *p_gem2, gem_O *p_gem_combined)
{
p_gem_combined->father=p_gem1;
p_gem_combined->mother=p_gem2;
int delta = p_gem1->grade - p_gem2->grade;
switch (delta){
case 0:
gem_comb_eq(p_gem1, p_gem2, p_gem_combined);
break;
case 1:
gem_comb_d1(p_gem1, p_gem2, p_gem_combined);
break;
case -1:
gem_comb_d1(p_gem2, p_gem1, p_gem_combined);
break;
default:
gem_comb_gn(p_gem1, p_gem2, p_gem_combined);
break;
}
}
inline void gem_init(gem_O *p_gem, int grd, double leech)
{
p_gem->grade=grd;
p_gem->leech=leech;
p_gem->father=NULL;
p_gem->mother=NULL;
}
// -----------------
// Pool init section
// -----------------
#include "1D_utils.h"
template<>
inline vector<pool_t<gem_O>> init_pool(int len, uint) {
return init_pool_1D<gem_O>(len);
}
#endif // _LEECH_UTILS_H