(m: list[list[tuple[str,int]]], dmg: dict[str,int])
| 26 | return (rt,ct) if rt and ct else None |
| 27 | |
| 28 | def 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 | |
| 47 | def count_left(m: list[list[tuple[str,int]]]) -> tuple[int,int]: |
| 48 | counts = defaultdict[str,int](int) |
no test coverage detected