-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22.py
88 lines (75 loc) · 2.91 KB
/
22.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
SPELL_COST = {'M': 53, 'D': 73, 'S': 113, 'P': 173, 'R': 229}
def battle(player_hp, player_mana, boss_hp, mana_spent, poison_left,
shield_left, recharge_left, chain, first, spell, hard_mode):
if hard_mode:
player_hp -= 1
if player_hp <= 0:
return
if not first:
if SPELL_COST[spell] > player_mana:
return
elif spell == 'S' and shield_left > 1:
return
elif spell == 'P' and poison_left > 1:
return
elif spell == 'R' and recharge_left > 1:
return
else:
player_hp, player_mana, boss_hp, poison_left, shield_left, recharge_left, armor = handle_buffs(
player_hp, player_mana, boss_hp, poison_left, shield_left,
recharge_left)
player_hp, player_mana, boss_hp, poison_left, shield_left, recharge_left = my_turn(
spell, player_hp, player_mana, boss_hp, poison_left,
shield_left, recharge_left)
player_hp, player_mana, boss_hp, poison_left, shield_left, recharge_left, armor = handle_buffs(
player_hp, player_mana, boss_hp, poison_left, shield_left,
recharge_left)
player_hp = boss_turn(player_hp, armor)
if boss_hp <= 0:
mana_spent_wins.add(mana_spent)
return
elif player_hp <= 0 or player_mana <= 0 or mana_spent >= min(
mana_spent_wins):
return
for spell in 'RSPDM':
battle(player_hp, player_mana, boss_hp, mana_spent + SPELL_COST[spell],
poison_left, shield_left, recharge_left, chain + spell, False,
spell, hard_mode)
def handle_buffs(player_hp, player_mana, boss_hp, poison_left, shield_left,
recharge_left):
if poison_left:
boss_hp -= 3
poison_left = max(poison_left - 1, 0)
if shield_left:
armor = 7
shield_left = max(shield_left - 1, 0)
else:
armor = 0
if recharge_left:
player_mana += 101
recharge_left = max(recharge_left - 1, 0)
return player_hp, player_mana, boss_hp, poison_left, shield_left, recharge_left, armor
def my_turn(spell, player_hp, player_mana, boss_hp, poison_left, shield_left,
recharge_left):
if spell == 'M':
boss_hp -= 4
elif spell == 'D':
boss_hp -= 2
player_hp += 2
elif spell == 'S':
shield_left = 6
elif spell == 'P':
poison_left = 6
elif spell == 'R':
recharge_left = 5
player_mana -= SPELL_COST[spell]
return player_hp, player_mana, boss_hp, poison_left, shield_left, recharge_left
def boss_turn(player_hp, armor):
player_hp -= max(9 - armor, 1)
return player_hp
mana_spent_wins = set([5000])
battle(50, 500, 51, 0, 0, 0, 0, '', True, '', False)
print(min(mana_spent_wins))
mana_spent_wins = set([5000])
battle(50, 500, 51, 0, 0, 0, 0, '', True, '', True)
print(min(mana_spent_wins))