def can_block(self, loc, state: gamelib.AdvancedGameState): target = state.game_map.BOTTOM_LEFT if loc[1] > 13 else state.game_map.BOTTOM_RIGHT path = state.find_path_to_edge(loc, target) for i in path: if i[1] < 17: f = -1 if target == state.game_map.BOTTOM_RIGHT else 1 return [i[0], 13], [i[0] + f, 13] return None, None
def simulate(self, state: gamelib.AdvancedGameState, unit_type, spawn_loc=(13, 0), num_units=1): map = state.game_map """ TODO: ENCRYPTORS """ target_edge = map.TOP_RIGHT if spawn_loc[0] < 14 else map.TOP_LEFT path = state.find_path_to_edge(spawn_loc, target_edge) total_dmg = 0 total_cores = 0 frames = 2 if unit_type == PING else 4 dmg = 0 if unit_type == SCRAMBLER else (1 if unit_type == PING else 3) for i in range(num_units): map.add_unit(unit_type, spawn_loc) idx = 0 remaining = map[spawn_loc] map.remove_unit(spawn_loc) pings = 0 while idx < len(path): loc = path[idx] for i in remaining: i.x = loc[0] i.y = loc[1] map[loc].append(i) for i in range(frames): defense_dmg = 4 * len(state.get_attackers(loc, 0)) our_dmg = len(map[loc]) * dmg initial = len(map[loc]) if map[loc]: target = state.get_target(map[loc][0]) else: break if target: target.stability -= our_dmg total_dmg += our_dmg total_cores += (our_dmg / target.max_stability) * target.cost if target.stability < 0: map.remove_unit([target.x, target.y]) dead = 0 for i in range(initial): if defense_dmg <= 0 or dead == len(map[loc]): break # Killed one, did they kill more if defense_dmg >= map[loc][dead].stability: defense_dmg -= map[loc][dead].stability dead += 1 # They didn't kill this one else: map[loc][dead].stability -= defense_dmg break # kill the dead ones for i in range(dead): map[loc].pop(0) remaining = map[loc] pings = remaining if len(remaining) == 0: break map.remove_unit(loc) idx += 1 if loc[1] > 14: mod_path = state.find_path_to_edge(spawn_loc, target_edge) if path != mod_path and loc in mod_path: idx = mod_path.index(loc) + 1 path = mod_path return 3.5 * len(pings) + total_cores