MCPcopy Create free account
hub / github.com/AxlLind/AdventOfCode / step

Function step

2018/src/15.py:28–45  ·  view source on GitHub ↗
(m: list[list[tuple[str,int]]], dmg: dict[str,int])

Source from the content-addressed store, hash-verified

26 return (rt,ct) if rt and ct else None
27
28def step(m: list[list[tuple[str,int]]], dmg: dict[str,int]):
29 moved = set()
30 for r,c in product(range(len(m)),range(len(m[0]))):
31 if m[r][c][0] not in "GE" or (r,c) in moved:
32 continue
33 enemy = 'E' if m[r][c][0] == 'G' else 'G'
34 target = get_target(m,r,c,enemy)
35 if not target:
36 if s := bfs(m,r,c,enemy):
37 rt,ct = s
38 m[rt][ct], m[r][c] = m[r][c], ('.',0)
39 moved.add((rt,ct))
40 target = get_target(m,rt,ct,enemy)
41 if target:
42 rt,ct = target
43 m[rt][ct] = (enemy, m[rt][ct][1] - dmg[enemy])
44 if m[rt][ct][1] <= 0:
45 m[rt][ct] = ('.',0)
46
47def count_left(m: list[list[tuple[str,int]]]) -> tuple[int,int]:
48 counts = defaultdict[str,int](int)

Callers 1

simulateFunction · 0.70

Calls 2

get_targetFunction · 0.85
bfsFunction · 0.70

Tested by

no test coverage detected