-
Notifications
You must be signed in to change notification settings - Fork 0
/
fatigue.py
70 lines (55 loc) · 2.12 KB
/
fatigue.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
#!/bin/python3
import math
from collections import defaultdict
# Gets the trapezoidal number starting at k
# a.k.a. getting the total fatigue damage for calc mode
# See README.md for more info about the formula
def trapezoidalNumber(l, k):
return int(l*(2*(k-1)+l+1)/2) if (l >= 0 and k >= 0) else 0
# Finds valid l in the previous formula (for lethal mode)
# a.k.a. getting the number of turns to reach a fatigue damage
# See README.md for more info about the formula
def findTrapezoidalNumber(n, k):
return int(0.5 * (math.sqrt(4*k**2-4*k+8*n+1) - 2*k + 1)) \
if (n >= 0 and k >= 0) else 0
# Mode 1: calculates turns needed for X cumulative fatigue damage
def lethalMode():
# Cleanly getting the values:
while True:
try:
maxDmg = int(input("Please input the damage needed for lethal: "))
dmg = int(input("Starting at how much damage? (default is 1): ")
or 1)
except ValueError:
print("ERROR: Your input value was invalid.\n")
else:
break
print(f">> You will need {findTrapezoidalNumber(maxDmg, dmg)} fatigue"
" turn(s) for that sweet lethal\n")
# Mode 2: calculates cumulative fatigue damage
def calcMode():
# Cleanly getting the values:
while True:
try:
turns = int(input("Please input the fatigue turns: "))
dmg = int(input("Starting at how much damage? (default is 1): ")
or 1)
except ValueError:
print("ERROR: Your input value was invalid.\n")
else:
break
print(f">> It will deal {trapezoidalNumber(turns, dmg)} damage\n")
def main():
print("~ Hearthstone Fatigue Calculator by Mario O.M. ~")
while True:
print("1. Lethal mode: turns needed for X damage\n"
"2. Calculator mode: damage dealt in X turns")
mode = input("Please type the desired mode (1 or 2): ").strip()
if mode == "1":
lethalMode()
elif mode == "2":
calcMode()
else:
print("ERROR: Please select a valid mode.\n")
if __name__ == '__main__':
main()