Fix linting.

This commit is contained in:
Mikael CAPELLE
2024-12-03 14:11:29 +01:00
parent cb0145baa2
commit acb767184e
49 changed files with 1160 additions and 353 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
import heapq
import sys
from typing import Literal, TypeAlias
from typing import Literal, TypeAlias, cast
PlayerType: TypeAlias = Literal["player", "boss"]
SpellType: TypeAlias = Literal["magic missile", "drain", "shield", "poison", "recharge"]
@@ -18,6 +18,16 @@ Node: TypeAlias = tuple[
tuple[tuple[SpellType, int], ...],
]
ATTACK_SPELLS: list[tuple[SpellType, int, int, int]] = [
("magic missile", 53, 4, 0),
("drain", 73, 2, 2),
]
BUFF_SPELLS: list[tuple[BuffType, int, int]] = [
("shield", 113, 6),
("poison", 173, 6),
("recharge", 229, 5),
]
def play(
player_hp: int,
@@ -97,10 +107,7 @@ def play(
else:
buff_types = {b for b, _ in buffs}
for spell, cost, damage, regeneration in (
("magic missile", 53, 4, 0),
("drain", 73, 2, 2),
):
for spell, cost, damage, regeneration in ATTACK_SPELLS:
if player_mana < cost:
continue
@@ -114,15 +121,11 @@ def play(
player_armor,
max(0, boss_hp - damage),
buffs,
spells + ((spell, cost),),
spells + cast("tuple[tuple[SpellType, int]]", ((spell, cost),)),
),
)
for buff_type, buff_cost, buff_length in (
("shield", 113, 6),
("poison", 173, 6),
("recharge", 229, 5),
):
for buff_type, buff_cost, buff_length in BUFF_SPELLS:
if buff_type in buff_types:
continue
@@ -138,8 +141,14 @@ def play(
player_mana - buff_cost,
player_armor + 7 * (buff_type == "shield"),
boss_hp,
buffs + ((buff_type, buff_length),),
spells + ((buff_type, buff_cost),),
buffs
+ cast(
"tuple[tuple[BuffType, int]]", ((buff_type, buff_length),)
),
spells
+ cast(
"tuple[tuple[SpellType, int]]", ((buff_type, buff_cost),)
),
),
)

View File

@@ -10,7 +10,8 @@ lines = sys.stdin.read().splitlines()
distances: dict[str, dict[str, int]] = defaultdict(dict)
for line in lines:
origin, destination, length = cast(
tuple[str, str, int], parse.parse("{} to {} = {:d}", line) # type: ignore
tuple[str, str, int],
parse.parse("{} to {} = {:d}", line), # type: ignore
)
distances[origin][destination] = distances[destination][origin] = length