forked from Repiked/Gimkit-Optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc-gimkit-strategy.py
222 lines (195 loc) · 10.2 KB
/
calc-gimkit-strategy.py
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
from math import ceil
import sys
initial_money = 0
goal = -1
comprehensive = False
max_num_steps = -1
if len(sys.argv) > 1:
initial_money = int(sys.argv[1])
if len(sys.argv) > 2:
goal = int(sys.argv[2])
if len(sys.argv) > 3:
comprehensive = bool(int(sys.argv[3]))
if len(sys.argv) > 4:
max_num_steps = int(sys.argv[4])
moneys = [1, 5, 50, 100, 500, 2000, 5000, 10000, 250000, 1000000]
money_costs = [
[0, 10, 100, 1000, 10000, 75000, 300000, 1000000, 10000000, 100000000],
[0, 8, 75, 750, 7500, 56250, 225000, 750000, 7500000, 75000000]
]
streaks = [1, 3, 10, 50, 250, 1200, 6500, 35000, 175000, 1000000]
streak_costs = [
[0, 20, 200, 2000, 20000, 200000, 2000000, 20000000, 200000000, 2000000000],
[0, 15, 150, 1500, 15000, 150000, 1500000, 15000000, 150000000, 1500000000]
]
multipliers = [1, 1.5, 2, 3, 5, 8, 12, 18, 30, 100]
multiplier_costs = [
[0, 50, 300, 2000, 12000, 85000, 700000, 6500000, 65000000, 1000000000],
[0, 38, 225, 1500, 9000, 63750, 525000, 4875000, 48750000, 750000000]
]
benefit_arrays = [0, moneys, streaks, multipliers]
cost_arrays = [0, money_costs, streak_costs, multiplier_costs]
powerup_base_costs = [0, 0, 0, 0, 250, 20, 50, 1000, 500, 1200]
powerup_percentage_costs = [0, 0, 0, 0, .16, .03, .06, .30, .06, .32]
def calc_powerup_cost(index, amount):
return 5*int(ceil((powerup_percentage_costs[index]*amount+powerup_base_costs[index])/5))
def calc_optimal_benefit(arr, cur_benefit, amount):
while cur_benefit+1 < len(arr) and amount >= arr[cur_benefit+1]:
cur_benefit += 1
return cur_benefit
def calc_gain_per_q(tpl):
return int(ceil((moneys[tpl[1]]+streaks[tpl[2]]*tpl[10])*multipliers[tpl[3]]))
def is_completely_dominant(state, state2):
if (state[1] >= state2[1] + 2 + comprehensive and state[2] >= state2[2] + 2 + comprehensive and state[3] >= state2[3] + 2 + comprehensive):
return True
for i in range(len(state)):
if (i != 10 and state[i] < state2[i]):
return False
for i in range(len(state)):
if (i != 10 and state[i] != state2[i]):
break
if (i == 10 and state[i] > state2[i]):
return True
return True
# Tuple: (Money, Money per Q, Streak, Multiplier, Discount, Mini Bonus, Mega Bonus, Rebooter, [Minute to Win it, Quadgrader, Streak Count])
cur_queue = [(initial_money+1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)]
prev_cur_queue = []
next_queue = []
prev_next_queue = []
prev = {}
final_state = None
debug_i = -1
i = 0
while True:
for state in cur_queue:
for benefit_index in range(1, 4):
optimal_benefit = calc_optimal_benefit(cost_arrays[benefit_index][state[4]], state[benefit_index], state[0])
for possible_benefit in range(state[benefit_index]+1 if comprehensive else max(state[benefit_index]+1, optimal_benefit), optimal_benefit + 1):
next_queue.append((state[0]-cost_arrays[benefit_index][state[4]][possible_benefit],)+state[1:benefit_index]+(possible_benefit,)+state[(benefit_index+1):10]+(0,)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
for powerup_index in range(4, 10):
powerup_cost = calc_powerup_cost(powerup_index, state[0])
if state[powerup_index] == 0 and powerup_cost < state[0]:
next_queue.append((state[0]-powerup_cost,)+state[1:powerup_index]+(1,)+state[(powerup_index+1):10]+(state[10],)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
next_queue.append((state[0]+calc_gain_per_q(state),)+state[1:10]+(min(state[10] + 1, 99),)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
if state[5] == 1:
next_queue.append((state[0]+2*calc_gain_per_q(state),)+state[1:5]+(-1,)+state[6:10]+(state[10],)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
if state[6] == 1:
next_queue.append((state[0]+5*calc_gain_per_q(state),)+state[1:6]+(-1,)+state[7:10]+(state[10],)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
if state[5] == 1 and state[6] == 1:
next_queue.append((state[0]+10*calc_gain_per_q(state),)+state[1:5]+(-1,-1)+state[7:10]+(state[10],)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
if state[7] == 1:
next_queue.append(state[0:4]+(abs(state[4]), abs(state[5]), abs(state[6]), -1, abs(state[8]), abs(state[9]))+(state[10],)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
if state[8] == 1:
next_queue.append((state[0]+2*calc_gain_per_q(state),)+state[1:8]+(-1,)+state[9:10]+(state[10],)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
if state[5] == 1 and state[6] == 1 and state[8] == 1:
next_queue.append((state[0]+20*calc_gain_per_q(state),)+state[1:5]+(-1,-1)+ state[7:8] + (-1,) + (state[9], state[10]) + state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
if state[9] == 1:
next_queue.append((state[0],)+(min(9, state[1]+1), min(9, state[2]+1), min(9, state[3]+1))+(state[4:9])+(-1,)+(0,)+state[11:])
prev_next_queue.append(state)
if i == debug_i: print("K", next_queue[-1], prev_next_queue[-1])
sorted_lsts = sorted(zip(next_queue, prev_next_queue))
next_queue = [x for x,_ in sorted_lsts]
prev_next_queue = [x for _,x in sorted_lsts]
cur_queue = []
prev_cur_queue = []
for j, state in enumerate(next_queue):
indexes_to_be_removed = []
for k, state2 in enumerate(cur_queue):
if (is_completely_dominant(state, state2)):
indexes_to_be_removed.insert(0, k)
for index in indexes_to_be_removed:
del cur_queue[index]
del prev_cur_queue[index]
cur_queue.append(state)
prev_cur_queue.append(prev_next_queue[j])
if i == debug_i: print(state, prev_next_queue[j])
for j, state in enumerate(cur_queue):
prev[state] = prev_cur_queue[j]
if goal == -1:
if state[1] == 9 and state[2] == 9 and state[3] == 9:
final_state = state
break
if final_state != None: break
if goal > -1 and cur_queue[-1][0] >= goal:
final_state = cur_queue[-1]
break
if max_num_steps > -1 and i+2 >= max_num_steps:
final_state = cur_queue[-1]
break
next_queue = []
prev_next_queue = []
i += 1
# print(i+1, cur_queue)
cur_state = final_state
lst = []
while cur_state in prev:
lst.insert(0, cur_state)
cur_state = prev[cur_state]
lst.insert(0, cur_state)
print("Number of Steps:", len(lst))
numQuestions = 0
for i, tpl in enumerate(lst):
print(str(i+1)+". ", end="")
if i == 0 or lst[i-1][0]+calc_gain_per_q(lst[i-1]) == tpl[0]:
print("Answer 1 question, bringing your total up to $"+str(tpl[0]))
numQuestions += 1
elif lst[i-1][0]+2*calc_gain_per_q(lst[i-1]) == tpl[0]:
print("Answer 1 question using the mini bonus, bringing your total up to $"+str(tpl[0]))
numQuestions += 1
elif lst[i-1][0]+5*calc_gain_per_q(lst[i-1]) == tpl[0]:
print("Answer 1 question using the mega bonus, bringing your total up to $"+str(tpl[0]))
numQuestions += 1
elif lst[i-1][0]+10*calc_gain_per_q(lst[i-1]) == tpl[0]:
print("Answer 1 question using the mini and mega bonuses, bringing your total up to $"+str(tpl[0]))
numQuestions += 1
elif lst[i-1][0]+20*calc_gain_per_q(lst[i-1]) == tpl[0]:
print("Answer 1 question using the mini, minute, and mega bonuses, bringing your total up to $"+str(tpl[0]))
numQuestions += 1
elif tpl[7] < lst[i-1][7]:
print("Use the rebooter to regenerate your previously bought powerups.")
elif tpl[1] > lst[i-1][1] and tpl[2] > lst[i-1][2]:
print("Use the Quadgrader to increase all your levels by one.")
elif tpl[1] > lst[i-1][1]:
print("Buy the Level "+str(tpl[1]+1)+" ($"+str(moneys[tpl[1]])+") money per question upgrade for $"+str(money_costs[tpl[4]][tpl[1]])+", making your total $"+str(tpl[0]))
elif tpl[2] > lst[i-1][2]:
print("Buy the Level "+str(tpl[2]+1)+" ($"+str(streaks[tpl[2]])+") streak bonus upgrade for $"+str(streak_costs[tpl[4]][tpl[2]])+", making your total $"+str(tpl[0]))
elif tpl[3] > lst[i-1][3]:
print("Buy the Level "+str(tpl[3]+1)+" ("+str(multipliers[tpl[3]])+"x) multiplier upgrade for $"+str(multiplier_costs[tpl[4]][tpl[3]])+", making your total $"+str(tpl[0]))
elif tpl[4] > lst[i-1][4]:
print("Buy and use the discounter for $"+str(calc_powerup_cost(4, lst[i-1][0]))+", making your total $"+str(tpl[0]))
elif tpl[5] > lst[i-1][5]:
print("Buy the mini bonus for $"+str(calc_powerup_cost(5, lst[i-1][0]))+", making your total $"+str(tpl[0]))
elif tpl[6] > lst[i-1][6]:
print("Buy the mega bonus for $"+str(calc_powerup_cost(6, lst[i-1][0]))+", making your total $"+str(tpl[0]))
elif tpl[7] > lst[i-1][7]:
print("Buy the rebooter for $"+str(calc_powerup_cost(7, lst[i-1][0]))+", making your total $"+str(tpl[0]))
elif tpl[8] > lst[i-1][8]:
print("Buy the minute to win it for $"+str(calc_powerup_cost(8, lst[i-1][0]))+", making your total $"+str(tpl[0]))
elif tpl[9] > lst[i-1][9]:
print("Buy the Quadgrader for $"+str(calc_powerup_cost(9, lst[i-1][0]))+", making your total $"+str(tpl[0]))
else:
print("ERROR: We don't know what to do! But here's a hint:", lst[i-1], tpl)
# print(tpl)
print(lst[-1][1])
print(lst[-1][2])
print(lst[-1][3])
print(calc_gain_per_q(final_state))
print("Number of Questions: " + str(numQuestions))