def get_best_shelter(life): _best_shelter = {"distance": -1, "shelter": None} if life["group"] and groups.get_shelter(life, life["group"]): _shelter = groups.get_shelter(life, life["group"]) if _shelter: _nearest_chunk_key = references.find_nearest_key_in_reference(life, _shelter) _shelter_center = [int(val) + (WORLD_INFO["chunk_size"] / 2) for val in _nearest_chunk_key.split(",")] _dist = numbers.distance(life["pos"], _shelter_center) judge_chunk(life, _nearest_chunk_key) if _dist <= logic.time_until_midnight() * life["speed_max"]: print life["name"], "can get to shelter in time" return _nearest_chunk_key else: print life["name"], "cant get to shelter in time" print life["name"], life["group"], [ chunk_id for chunk_id in life["known_chunks"] if chunks.get_flag(life, chunk_id, "shelter") ] for chunk_key in [chunk_id for chunk_id in life["known_chunks"] if chunks.get_flag(life, chunk_id, "shelter")]: chunk_center = [int(val) + (WORLD_INFO["chunk_size"] / 2) for val in chunk_key.split(",")] _score = numbers.distance(life["pos"], chunk_center) if not _best_shelter["shelter"] or _score < _best_shelter["distance"]: _best_shelter["shelter"] = chunk_key _best_shelter["distance"] = _score return _best_shelter["shelter"]
def get_best_shelter(life): _best_shelter = {'distance': -1, 'shelter': None} if life['group'] and groups.get_shelter(life, life['group']): _shelter = groups.get_shelter(life, life['group']) if _shelter: _nearest_chunk_key = references.find_nearest_key_in_reference(life, _shelter) _shelter_center = [int(val)+(WORLD_INFO['chunk_size']/2) for val in _nearest_chunk_key.split(',')] _dist = bad_numbers.distance(life['pos'], _shelter_center) judge_chunk(life, _nearest_chunk_key) if _dist <= logic.time_until_midnight()*life['speed_max']: print life['name'],'can get to shelter in time' return _nearest_chunk_key else: print life['name'],'cant get to shelter in time' for chunk_key in [chunk_id for chunk_id in life['known_chunks'] if chunks.get_flag(life, chunk_id, 'shelter')]: chunk_center = [int(val)+(WORLD_INFO['chunk_size']/2) for val in chunk_key.split(',')] _score = bad_numbers.distance(life['pos'], chunk_center) if not _best_shelter['shelter'] or _score<_best_shelter['distance']: _best_shelter['shelter'] = chunk_key _best_shelter['distance'] = _score return _best_shelter['shelter']
def _get_nearest_known_camp(life): _nearest_camp = {'camp': None, 'score': -1} for camp in [life['known_camps'][i] for i in life['known_camps']]: _key = references.find_nearest_key_in_reference(life, get_camp(camp['id'])['reference']) _center = [int(val)+(WORLD_INFO['chunk_size']/2) for val in _key.split(',')] _distance = bad_numbers.distance(life['pos'], _center) if not _nearest_camp['camp'] or _distance>_nearest_camp['score']: _nearest_camp['camp'] = camp _nearest_camp['score'] = _distance return _nearest_camp
def _get_nearest_known_camp(life): _nearest_camp = {'camp': None, 'score': -1} for camp in [life['known_camps'][i] for i in life['known_camps']]: _key = references.find_nearest_key_in_reference( life, get_camp(camp['id'])['reference']) _center = [ int(val) + (WORLD_INFO['chunk_size'] / 2) for val in _key.split(',') ] _distance = numbers.distance(life['pos'], _center) if not _nearest_camp['camp'] or _distance > _nearest_camp['score']: _nearest_camp['camp'] = camp _nearest_camp['score'] = _distance return _nearest_camp
def explore_unknown_chunks(life): if life["path"]: return True _chunk_key = references.path_along_reference(life, "roads") if not _chunk_key: _best_reference = references._find_best_unknown_reference(life, "roads")["reference"] if not _best_reference: return False _chunk_key = references.find_nearest_key_in_reference(life, _best_reference, unknown=True, threshold=15) if not _chunk_key: return False _walkable_area = chunks.get_walkable_areas(_chunk_key) if not _walkable_area: print "no walkable area" return False _closest_pos = {"pos": None, "distance": -1} for pos in _walkable_area: _distance = numbers.distance(life["pos"], pos) if _distance <= 1: _closest_pos["pos"] = pos break if not _closest_pos["pos"] or _distance < _closest_pos["distance"]: _closest_pos["pos"] = pos _closest_pos["distance"] = _distance lfe.clear_actions(life) lfe.add_action(life, {"action": "move", "to": _closest_pos["pos"]}, 200) return True