Skip to content

Commit

Permalink
replace LEVEL_GRAPH with level calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
HorizonCode committed Mar 13, 2024
1 parent 12f28cb commit 0fe11ed
Showing 1 changed file with 15 additions and 111 deletions.
126 changes: 15 additions & 111 deletions app/constants/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,32 @@

import math

LEVEL_GRAPH = [
0,
30000,
130000,
340000,
700000,
1250000,
2030000,
3080000,
4440000,
6150000,
8250000,
10780000,
13780000,
17290000,
21350000,
26000000,
31280000,
37230000,
43890000,
51300000,
59500000,
68530000,
78430000,
89240000,
101000000,
113750000,
127530000,
142380000,
158340000,
175450000,
193750000,
213280000,
234080000,
256190000,
279650000,
304500000,
330780000,
358530000,
387790000,
418600000,
451000000,
485030000,
520730000,
558140000,
597300000,
638250000,
681030000,
725680000,
772240000,
820750000,
871250000,
923780000,
978380000,
1035090000,
1093950000,
1155000000,
1218280000,
1283830000,
1351690001,
1421900001,
1494500002,
1569530004,
1647030007,
1727040013,
1809600024,
1894750043,
1982530077,
2072980138,
2166140248,
2262050446,
2360750803,
2462281446,
2566682603,
2673994685,
2784258433,
2897515180,
3013807324,
3133179183,
3255678529,
3381359353,
3510286835,
3642546304,
3778259346,
3917612824,
4060911082,
4208669948,
4361785907,
4521840633,
4691649139,
4876246450,
5084663609,
5333124496,
5650800094,
6090166168,
6745647103,
7787174786,
9520594614,
12496396305,
17705429349,
26931190829,
]


def get_required_score_for_level(level: int) -> int:
if level <= 0:
if level < 1:
return 0

if level <= 100:
return LEVEL_GRAPH[level - 1]
return LEVEL_GRAPH[99] + 100000000000 * int(level - 100)
return math.ceil(
(5000 / 3) * (4 * level**3 - 3 * level**2 - level)
+ 1.25 * 1.8 ** (level - 60)
)
else:
return math.ceil(26931190827 + 99999999999 * (level - 100) + 2)


def get_level(score: int) -> int:
if score <= 0:
return 1

if score >= LEVEL_GRAPH[99]:
return 100 + int((score - LEVEL_GRAPH[99]) / 100000000000)
if score >= get_required_score_for_level(99):
return 100 + int((score - get_required_score_for_level(99)) / 100000000000)

levels = [get_required_score_for_level(level) for level in range(1, 101)]

for idx, v in enumerate(LEVEL_GRAPH, start=0):
if v > score:
return idx
for level, level_score in enumerate(levels, start=1):
if score <= level_score:
return level

return 1

Expand Down

0 comments on commit 0fe11ed

Please sign in to comment.