def search_for_target(life, target_id): #TODO: Variable size instead of hardcoded _know = brain.knows_alife_by_id(life, target_id) _size = 30 if brain.alife_has_flag(life, target_id, 'search_map'): _search_map = brain.get_alife_flag(life, target_id, 'search_map') else: _search_map = maps.create_search_map(life, _know['last_seen_at'], _size) brain.flag_alife(life, target_id, 'search_map', value=_search_map) lfe.stop(life) lfe.walk_to(life, _know['last_seen_at'][:2]) if life['path'] or lfe.find_action(life, matches=[{'action': 'move'}]): return False _lowest = {'score': -1, 'pos': None} _x_top_left = numbers.clip(_know['last_seen_at'][0]-(_size/2), 0, MAP_SIZE[0]) _y_top_left = numbers.clip(_know['last_seen_at'][1]-(_size/2), 0, MAP_SIZE[1]) for x in range(0, _size): _x = _x_top_left+x if _x >= MAP_SIZE[0]-1: continue for y in range(0, _size): _y = _y_top_left+y if _y >= MAP_SIZE[1]-1: continue if not _search_map[y, x]: continue if sight.can_see_position(life, (_x, _y)): _search_map[y, x] = 0 if _search_map[y, x]>0 and (not _lowest['pos'] or _search_map[y, x] <= _lowest['score']): _lowest['score'] = _search_map[y, x] _lowest['pos'] = (_x, _y, x, y) if _lowest['pos']: x, y, _x, _y = _lowest['pos'] if travel_to_position(life, (x, y, _know['last_seen_at'][2]), stop_on_sight=True): _search_map[_y, _x] = 0 else: _know['escaped'] = 2
def search_for_target(life, target_id): #TODO: Variable size instead of hardcoded _know = brain.knows_alife_by_id(life, target_id) _size = 30 _timer = brain.get_flag(life, 'search_time') _chunk_path = alife.brain.get_flag(life, 'chunk_path') if _chunk_path: travel_to_position(life, _chunk_path['end'], force=True) return False if _timer > 0: brain.flag(life, 'search_time', _timer - 1) return False if brain.alife_has_flag(life, target_id, 'search_map'): _search_map = brain.get_alife_flag(life, target_id, 'search_map') else: _search_map = maps.create_search_map(life, _know['last_seen_at'], _size) brain.flag_alife(life, target_id, 'search_map', value=_search_map) lfe.walk_to(life, _know['last_seen_at']) brain.flag(life, 'search_time', 12) return False _lowest = {'score': -1, 'pos': None} _x_top_left = bad_numbers.clip(_know['last_seen_at'][0] - (_size / 2), 0, MAP_SIZE[0]) _y_top_left = bad_numbers.clip(_know['last_seen_at'][1] - (_size / 2), 0, MAP_SIZE[1]) for x in range(0, _size): _x = _x_top_left + x if _x >= MAP_SIZE[0] - 1: continue for y in range(0, _size): _y = _y_top_left + y if _y >= MAP_SIZE[1] - 1: continue if not _search_map[y, x]: continue if sight.can_see_position(life, (_x, _y, _know['last_seen_at'][2]), get_path=True) or not lfe.can_walk_to( life, (_x, _y, _know['last_seen_at'][2])): _search_map[y, x] = 0 if _search_map[y, x] > 0 and ( not _lowest['pos'] or _search_map[y, x] < _lowest['score']): _lowest['score'] = _search_map[y, x] _lowest['pos'] = (_x, _y, x, y) if _lowest['pos']: x, y, _x, _y = _lowest['pos'] if travel_to_position(life, (x, y, _know['last_seen_at'][2]), stop_on_sight=False): _search_map[_y, _x] = 0 brain.flag( life, 'search_time', bad_numbers.clip( bad_numbers.distance(life['pos'], (x, y)) * .75, 5, 16)) else: _know['escaped'] = 2
def search_for_target(life, target_id): # TODO: Variable size instead of hardcoded _know = brain.knows_alife_by_id(life, target_id) _size = 30 _timer = brain.get_flag(life, "search_time") _chunk_path = alife.brain.get_flag(life, "chunk_path") if _chunk_path: travel_to_position(life, _chunk_path["end"], force=True) return False if _timer > 0: brain.flag(life, "search_time", _timer - 1) return False if brain.alife_has_flag(life, target_id, "search_map"): _search_map = brain.get_alife_flag(life, target_id, "search_map") else: _search_map = maps.create_search_map(life, _know["last_seen_at"], _size) brain.flag_alife(life, target_id, "search_map", value=_search_map) lfe.walk_to(life, _know["last_seen_at"]) brain.flag(life, "search_time", 12) return False _lowest = {"score": -1, "pos": None} _x_top_left = numbers.clip(_know["last_seen_at"][0] - (_size / 2), 0, MAP_SIZE[0]) _y_top_left = numbers.clip(_know["last_seen_at"][1] - (_size / 2), 0, MAP_SIZE[1]) for x in range(0, _size): _x = _x_top_left + x if _x >= MAP_SIZE[0] - 1: continue for y in range(0, _size): _y = _y_top_left + y if _y >= MAP_SIZE[1] - 1: continue if not _search_map[y, x]: continue if sight.can_see_position(life, (_x, _y, _know["last_seen_at"][2]), get_path=True) or not lfe.can_walk_to( life, (_x, _y, _know["last_seen_at"][2]) ): _search_map[y, x] = 0 if _search_map[y, x] > 0 and (not _lowest["pos"] or _search_map[y, x] < _lowest["score"]): _lowest["score"] = _search_map[y, x] _lowest["pos"] = (_x, _y, x, y) if _lowest["pos"]: x, y, _x, _y = _lowest["pos"] if travel_to_position(life, (x, y, _know["last_seen_at"][2]), stop_on_sight=False): _search_map[_y, _x] = 0 brain.flag(life, "search_time", numbers.clip(numbers.distance(life["pos"], (x, y)) * 0.75, 5, 16)) else: _know["escaped"] = 2
def search_for_target(life, target_id): #TODO: Variable size instead of hardcoded _know = brain.knows_alife_by_id(life, target_id) _size = 30 _timer = brain.get_flag(life, 'search_time') _chunk_path = alife.brain.get_flag(life, 'chunk_path') if _chunk_path: travel_to_position(life, _chunk_path['end'], force=True) return False if _timer>0: brain.flag(life, 'search_time', _timer-1) return False if brain.alife_has_flag(life, target_id, 'search_map'): _search_map = brain.get_alife_flag(life, target_id, 'search_map') else: _search_map = maps.create_search_map(life, _know['last_seen_at'], _size) brain.flag_alife(life, target_id, 'search_map', value=_search_map) lfe.walk_to(life, _know['last_seen_at']) brain.flag(life, 'search_time', 12) return False _lowest = {'score': -1, 'pos': None} _x_top_left = bad_numbers.clip(_know['last_seen_at'][0]-(_size/2), 0, MAP_SIZE[0]) _y_top_left = bad_numbers.clip(_know['last_seen_at'][1]-(_size/2), 0, MAP_SIZE[1]) for x in range(0, _size): _x = _x_top_left+x if _x >= MAP_SIZE[0]-1: continue for y in range(0, _size): _y = _y_top_left+y if _y >= MAP_SIZE[1]-1: continue if not _search_map[y, x]: continue if sight.can_see_position(life, (_x, _y, _know['last_seen_at'][2]), get_path=True) or not lfe.can_walk_to(life, (_x, _y, _know['last_seen_at'][2])): _search_map[y, x] = 0 if _search_map[y, x]>0 and (not _lowest['pos'] or _search_map[y, x] < _lowest['score']): _lowest['score'] = _search_map[y, x] _lowest['pos'] = (_x, _y, x, y) if _lowest['pos']: x, y, _x, _y = _lowest['pos'] if travel_to_position(life, (x, y, _know['last_seen_at'][2]), stop_on_sight=False): _search_map[_y, _x] = 0 brain.flag(life, 'search_time', bad_numbers.clip(bad_numbers.distance(life['pos'], (x, y))*.75, 5, 16)) else: _know['escaped'] = 2