def explore_known_chunks(life): #Our first order of business is to figure out exactly what we're looking for. #There's a big difference between exploring the map looking for a purpose and #exploring the map with a purpose. Both will use similar routines but I wager #it'll actually be a lot harder to do it without there being some kind of goal #to at least start us in the right direction. #This function will kick in only if the ALife is idling, so looting is handled #automatically. #Note: Determining whether this fuction should run at all needs to be done inside #the module itself. _chunk_key = brain.retrieve_from_memory(life, 'explore_chunk') _chunk = maps.get_chunk(_chunk_key) if life['path'] and chunks.position_is_in_chunk(lfe.path_dest(life), _chunk_key): return True if chunks.is_in_chunk(life, '%s,%s' % (_chunk['pos'][0], _chunk['pos'][1])): life['known_chunks'][_chunk_key]['last_visited'] = WORLD_INFO['ticks'] return False if not _chunk['ground']: return False _pos_in_chunk = random.choice(_chunk['ground']) lfe.walk_to(life, _pos_in_chunk) return True
def explore_known_chunks(life): # Our first order of business is to figure out exactly what we're looking for. # There's a big difference between exploring the map looking for a purpose and # exploring the map with a purpose. Both will use similar routines but I wager # it'll actually be a lot harder to do it without there being some kind of goal # to at least start us in the right direction. # This function will kick in only if the ALife is idling, so looting is handled # automatically. # Note: Determining whether this fuction should run at all needs to be done inside # the module itself. _chunk_key = brain.retrieve_from_memory(life, "explore_chunk") _chunk = maps.get_chunk(_chunk_key) if life["path"] and chunks.position_is_in_chunk(lfe.path_dest(life), _chunk_key): return True if chunks.is_in_chunk(life, "%s,%s" % (_chunk["pos"][0], _chunk["pos"][1])): life["known_chunks"][_chunk_key]["last_visited"] = WORLD_INFO["ticks"] return False if not _chunk["ground"]: return False _pos_in_chunk = random.choice(_chunk["ground"]) lfe.clear_actions(life) lfe.add_action(life, {"action": "move", "to": _pos_in_chunk}, 200) return True
def find_least_populated_key_in_reference(life, reference): _lowest = {'chunk_key': None, 'score': 0} for _key in reference: _chunk = maps.get_chunk(_key) _score = len(_chunk['life']) if chunks.is_in_chunk(life, _key) and _score == 1: _score = -1 if not _lowest['chunk_key'] or _score < _lowest['score']: _lowest['chunk_key'] = _key _lowest['score'] = _score if _score == -1: break return _lowest['chunk_key']
def find_least_populated_key_in_reference(life, reference): _lowest = {"chunk_key": None, "score": 0} for _key in reference: _chunk = maps.get_chunk(_key) _score = len(_chunk["life"]) if chunks.is_in_chunk(life, _key) and _score == 1: _score = -1 if not _lowest["chunk_key"] or _score < _lowest["score"]: _lowest["chunk_key"] = _key _lowest["score"] = _score if _score == -1: break return _lowest["chunk_key"]
def find_least_populated_key_in_reference(life, reference): _lowest = {'chunk_key': None, 'score': 0} for _key in reference: _chunk = maps.get_chunk(_key) _score = len(_chunk['life']) if chunks.is_in_chunk(life, _key) and _score == 1: _score = -1 if not _lowest['chunk_key'] or _score<_lowest['score']: _lowest['chunk_key'] = _key _lowest['score'] = _score if _score == -1: break return _lowest['chunk_key']