-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturnippatterns.cpp
171 lines (137 loc) · 4.84 KB
/
turnippatterns.cpp
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
#include "turnippatterns.h"
// from https://gist.github.com/Treeki/85be14d297c80c8b3c0a76375743325b
int intceil(float val)
{
return (int)(val + 0.99999f);
}
/* TURNIP PATTERN METHODS */
TurnipPattern::TurnipPattern(float minDecAmt, float maxDecAmt) : MIN_DEC_AMT{minDecAmt}, MAX_DEC_AMT{maxDecAmt}
{
}
UniquePriceSeqs TurnipPattern::getAllSeqs()
{
return allSeqs;
}
void TurnipPattern::price(int base, OnePriceSeq &p, int halfs, float lowBaseRate, float hiBaseRate, float minDecAmt, float maxDecAmt)
{
while (halfs > 0)
{
int minHalf = intceil(base * lowBaseRate);
int maxHalf = intceil(base * hiBaseRate);
p.push_back(std::make_pair(minHalf, maxHalf));
lowBaseRate -= maxDecAmt; // lowest base rate possible
hiBaseRate -= minDecAmt; // highest base rate possible
--halfs;
}
}
/* RANDOM PATTERN METHODS */
void RandomPat::calculate(int base)
{
for (int incOne = 0; incOne <= 6; ++incOne)
{
int temp = 7 - incOne;
for (int incThree = 0; incThree <= temp - 1; ++incThree)
{
int incTwo = temp - incThree;
for (int decOne = 2; decOne <= 3; ++decOne)
{
int decTwo = 5 - decOne;
OnePriceSeq seq; // one price seq, 6 pairs
// inc phase 1
price(base, seq, incOne, INC_MIN, INC_MAX, 0, 0);
// dec phase 1
price(base, seq, decOne, DEC_MIN, DEC_MAX, MIN_DEC_AMT, MAX_DEC_AMT);
// inc phase 2
price(base, seq, incTwo, INC_MIN, INC_MAX, 0, 0);
// dec phase 2
price(base, seq, decTwo, DEC_MIN, DEC_MAX, MIN_DEC_AMT, MAX_DEC_AMT);
// inc phase 3
price(base, seq, incThree, INC_MIN, INC_MAX, 0, 0);
// add to set
allSeqs.insert(seq);
}
}
}
}
/* LARGE PATTERN METHODS */
void LargePat::calculate(int base)
{
for (int simmerDec = 1; simmerDec <= 7; ++simmerDec)
{
int decPhase = HALF_DAYS - simmerDec - 5;
OnePriceSeq seq;
// simmering decrease
price(base, seq, simmerDec, SIMMER_DEC_MIN, SIMMER_DEC_MAX, MIN_DEC_AMT, MAX_DEC_AMT);
// boiling increase: 3 halves
for (auto &rate : BOIL_INC_MIN_MAX)
{
price(base, seq, 1, rate.first, rate.second, 0, 0);
}
// boiling decrease: 2 halves
for (auto &rate : BOIL_DEC_MIN_MAX)
{
price(base, seq, 1, rate.first, rate.second, 0, 0);
}
// rand decrease
price(base, seq, decPhase, RAND_DEC_MIN, RAND_DEC_MAX, 0, 0);
// add to set
allSeqs.insert(seq);
}
}
/* DEC PATTERN METHODS */
void DecPat::calculate(int base)
{
OnePriceSeq seq;
price(base, seq, HALF_DAYS, DEC_MIN, DEC_MAX, MIN_DEC_AMT, MAX_DEC_AMT);
// add to set
allSeqs.insert(seq);
}
/* SMALL PATTERN METHODS */
void SmallPat::calculate(int base)
{
for (int decOne = 0; decOne <= 7; ++decOne)
{
for (float maxRate : INC_BOUNDS)
{
OnePriceSeq seq;
// dec phase 1
price(base, seq, decOne, DEC_MIN, DEC_MAX, MIN_DEC_AMT, MAX_DEC_AMT);
// inc phase: 5 halves
price(base, seq, 2, INC_MIN, INC_MAX, 0, 0);
seq.push_back(std::make_pair(intceil(INC_MAX * base) - 1, intceil(maxRate * base) - 1)); // half 3
price(base, seq, 1, maxRate, maxRate, 0, 0); // half 4
seq.push_back(std::make_pair(intceil(INC_MAX * base) - 1, intceil(maxRate * base) - 1)); // half 5
// dec phase 2
price(base, seq, HALF_DAYS - decOne - 5, DEC_MIN, DEC_MAX, MIN_DEC_AMT, MAX_DEC_AMT);
// add to set
allSeqs.insert(seq);
}
}
}
AllPricePatterns::AllPricePatterns() : patterns{{new RandomPat(), new LargePat(), new DecPat(), new SmallPat()}}, allPrices{new AllPrices()}
{
for (int base = MIN_BASE; base <= MAX_BASE; ++base)
{
for (int i = 0; i < patterns.size(); ++i)
{
TurnipPattern *turnipPat = patterns[i];
turnipPat->calculate(base);
(*allPrices)[i][base] = turnipPat->getAllSeqs();
}
}
}
void AllPricePatterns::print() {
for (int i = 0; i < 4; ++i) {
std::cout << "======= PATTERN " << i << " =======" << std::endl;
for (int base = MIN_BASE; base <= MAX_BASE; ++base) {
std::cout << base << " AS BASE PRICE" << std::endl;
for (auto &priceSeq: (*allPrices)[i][base]) {
for (auto &prices: priceSeq) {
std::cout << prices.first << "," << prices.second << " ";
}
} // one price sequence
std::cout << std::endl;
}
std::cout << "================" << "=========" << std::endl;
}
}