def tick(life): if life['actions']: return True _needs_to_meet = brain.retrieve_from_memory(life, 'needs_to_meet') for need in _needs_to_meet: movement.collect_nearby_wanted_items(life, matches=need['match'], only_visible=False) break _needs_to_satisfy = brain.retrieve_from_memory(life, 'needs_to_satisfy') for need in _needs_to_satisfy: survival.satisfy(life, need)
def tick(life): if not lfe.execute_raw(life, 'discover', 'discover_type'): _lost_method = lfe.execute_raw(life, 'discover', 'when_lost') if _lost_method: if not life['path'] or not brain.retrieve_from_memory( life, 'discovery_lock'): if not 'scanned_chunks' in life['state_flags']: life['state_flags']['scanned_chunks'] = [] sight.scan_surroundings( life, _chunks=brain.get_flag(life, 'visible_chunks'), ignore_chunks=life['state_flags']['scanned_chunks']) _explore_chunk = chunks.find_best_chunk( life, ignore_starting=True, ignore_time=True, lost_method=_lost_method, only_recent=True) brain.store_in_memory(life, 'discovery_lock', True) brain.store_in_memory(life, 'explore_chunk', _explore_chunk) if not _explore_chunk: brain.flag(life, 'lost') return False survival.explore_known_chunks(life) else: return False
def has_needs_to_satisfy(life): _needs = brain.retrieve_from_memory(life, "needs_to_satisfy") if _needs: return True return False
def has_needs_to_satisfy(life): _needs = brain.retrieve_from_memory(life, 'needs_to_satisfy') if _needs: return True return False
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 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 get_targets(life, escaped_only=False, ignore_escaped=True, limit_distance=-1, filter_func=None): return _target_filter( life, brain.retrieve_from_memory(life, "targets"), escaped_only, ignore_escaped, limit_distance=limit_distance, filter_func=filter_func, )
def has_needs_to_meet(life): _needs = brain.retrieve_from_memory(life, "needs_to_meet") if not _needs: return False if len(_needs) > 0: return True return False
def tick(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map): if brain.retrieve_from_memory(life, 'active_goals'): print 'ACTIVE GOAL' * 100 goals.perform_goal(life, judgement.get_best_goal(life)) else: #if jobs.alife_has_job(life): # lfe.clear_actions(life) # return True jobs.work(life)
def has_needs_to_meet(life): _needs = brain.retrieve_from_memory(life, 'needs_to_meet') if not _needs: return False if len(_needs) > 0: return True return False
def find_known_items(life, matches={}, only_visible=True): _match = [] _could_meet_with = [] for need in brain.retrieve_from_memory(life, 'needs_to_meet'): _could_meet_with.extend(need['could_meet_with']) for item_uid in brain.get_matching_remembered_items(life, matches, no_owner=True, only_visible=only_visible): #TODO: Offload? _item = ITEMS[item_uid] _match.append(item_uid) return _match
def get_ready_combat_targets( life, escaped_only=False, ignore_escaped=False, recent_only=False, limit_distance=-1, filter_func=None ): _targets = _target_filter( life, brain.retrieve_from_memory(life, "combat_targets"), escaped_only, ignore_escaped, recent_only=recent_only, limit_distance=limit_distance, filter_func=filter_func, ) return [t for t in _targets if target_is_combat_ready(life, t)]
def find_known_items(life, matches={}, only_visible=True): _match = [] _could_meet_with = [] for need in brain.retrieve_from_memory(life, 'needs_to_meet'): _could_meet_with.extend(need['could_meet_with']) for item_uid in brain.get_matching_remembered_items( life, matches, no_owner=True, only_visible=only_visible): #TODO: Offload? _item = ITEMS[item_uid] _match.append(item_uid) return _match
def get_threats( life, escaped_only=False, ignore_lost=True, ignore_escaped=True, recent_only=False, limit_distance=-1, filter_func=None, ): return _target_filter( life, brain.retrieve_from_memory(life, "threats"), escaped_only, ignore_escaped, ignore_lost=ignore_lost, recent_only=recent_only, limit_distance=limit_distance, filter_func=filter_func, )
def tick(life): if not lfe.execute_raw(life, 'discover', 'discover_type'): _lost_method = lfe.execute_raw(life, 'discover', 'when_lost') if _lost_method: if not life['path'] or not brain.retrieve_from_memory(life, 'discovery_lock'): if not 'scanned_chunks' in life['state_flags']: life['state_flags']['scanned_chunks'] = [] sight.scan_surroundings(life, _chunks=brain.get_flag(life, 'visible_chunks'), ignore_chunks=life['state_flags']['scanned_chunks']) _explore_chunk = chunks.find_best_chunk(life, ignore_starting=True, ignore_time=True, lost_method=_lost_method, only_recent=True) brain.store_in_memory(life, 'discovery_lock', True) brain.store_in_memory(life, 'explore_chunk', _explore_chunk) if not _explore_chunk: brain.flag(life, 'lost') return False survival.explore_known_chunks(life) else: return False
def get_combat_targets(life, escaped_only=False, ignore_escaped=False, ignore_lost=True, recent_only=False, limit_distance=-1, filter_func=None): return _target_filter(life, brain.retrieve_from_memory(life, 'combat_targets'), escaped_only, ignore_escaped, recent_only=recent_only, ignore_lost=ignore_lost, limit_distance=limit_distance, filter_func=filter_func)
def has_unmet_needs(life): if len(brain.retrieve_from_memory(life, 'needs_unmet')) > 0: return True return False
def get_threats(life, escaped_only=False, ignore_lost=True, ignore_escaped=True, recent_only=False, limit_distance=-1, filter_func=None): return _target_filter(life, brain.retrieve_from_memory(life, 'threats'), escaped_only, ignore_escaped, ignore_lost=ignore_lost, recent_only=recent_only, limit_distance=limit_distance, filter_func=filter_func)
def get_ready_combat_targets(life, escaped_only=False, ignore_escaped=False, recent_only=False, limit_distance=-1, filter_func=None): _targets = _target_filter(life, brain.retrieve_from_memory(life, 'combat_targets'), escaped_only, ignore_escaped, recent_only=recent_only, limit_distance=limit_distance, filter_func=filter_func) return [t for t in _targets if target_is_combat_ready(life, t)]
def get_best_goal(life): for goal in brain.retrieve_from_memory(life, 'active_goals'): return goal return -1
def get_tension(life): return brain.retrieve_from_memory(life, "tension")
def get_best_goal(life): for goal in brain.retrieve_from_memory(life, "active_goals"): return goal return -1
def has_unmet_needs(life): if len(brain.retrieve_from_memory(life, "needs_unmet")) > 0: return True return False
def get_tension(life): return brain.retrieve_from_memory(life, 'tension')