def find_and_announce_shelter(life, group_id): if get_stage(life, group_id) >= STAGE_RAIDING: return False _shelter = get_shelter(life, group_id) if get_motive(life, group_id) == 'crime' and logic.is_night(): if _shelter: set_shelter(life, group_id, None) announce(life, group_id, 'update_group_shelter', filter_if=lambda alife_id: not get_shelter(LIFE[alife_id], group_id)) #print 'MOTIVATED BY CRIME' * 20 return False if _shelter: if get_stage(life, group_id) < STAGE_SETTLED: set_stage(life, group_id, STAGE_SETTLED) if references.is_in_reference(life['pos'], references.get_reference(_shelter)): announce(life, group_id, 'update_group_shelter', filter_if=lambda alife_id: get_shelter(LIFE[alife_id], group_id)==_shelter) else: find_shelter(life, group_id)
def find_and_announce_shelter(life, group_id): if get_stage(life, group_id) >= STAGE_RAIDING: return False _shelter = get_shelter(life, group_id) if get_motive(life, group_id) == 'crime' and logic.is_night(): if _shelter: set_shelter(life, group_id, None) announce(life, group_id, 'update_group_shelter', filter_if=lambda alife_id: not get_shelter( LIFE[alife_id], group_id)) #print 'MOTIVATED BY CRIME' * 20 return False if _shelter: if get_stage(life, group_id) < STAGE_SETTLED: set_stage(life, group_id, STAGE_SETTLED) if references.is_in_reference(life['pos'], references.get_reference(_shelter)): announce(life, group_id, 'update_group_shelter', filter_if=lambda alife_id: get_shelter( LIFE[alife_id], group_id) == _shelter) else: find_shelter(life, group_id)
def judge_camp(life, camp, for_founding=False): # This is kinda complicated so I'll do my best to describe what's happening. # The ALife keeps track of chunks it's aware of, which we'll use when # calculating how much of a camp we know about (value between 0..1) # First we score the camp based on what we DO know, which is pretty cut and dry: # # We consider: # How big the camp is vs. how many people we think we're going to need to fit in it (not a factor ATM) # A big camp won't be attractive to just one ALife, but a faction will love the idea of having a larger base # Distance from other camps # Certain ALife will prefer isolation # # After scoring this camp, we simply multiply by the percentage of the camp # that is known. This will encourage ALife to discover a camp first before # moving in. # In addition to all that, we want to prevent returning camps that are too close # to other camps. This is hardcoded (can't think of a reason why the ALife would want this) if for_founding: for _known_camp in [c["reference"] for c in life["known_camps"].values()]: for _pos1 in _known_camp: pos1 = [int(i) for i in _pos1.split(",")] for _pos2 in camp: pos2 = [int(i) for i in _pos2.split(",")] _dist = numbers.distance(pos1, pos2) / WORLD_INFO["chunk_size"] if _dist <= 15: return 0 _known_chunks_of_camp = references.get_known_chunks_in_reference(life, camp) _current_population = 0 _current_trust = 0 for _target in life["know"].values(): if not references.is_in_reference(_target["last_seen_at"], camp): continue _current_population += 1 if can_trust(life, _target["life"]["id"]): _current_trust += _target["trust"] else: _current_trust -= _target["danger"] _percent_known = len(_known_chunks_of_camp) / float(len(camp)) _score = _current_trust _camp = camps.get_camp_via_reference(camp) if _camp: _score += judge_group(life, camps.get_controlling_group(_camp)) if stats.desires_to_create_camp(life): _score += len(groups.get_group(life, life["group"])["members"]) / 2 <= len(_known_chunks_of_camp) # TODO: Why does this cause a crash? # return int(round(_percent_known*10)) # print 'camp score:',(len(camp)*_percent_known),_score,(len(camp)*_percent_known)*_score return (len(camp) * _percent_known) * _score
def judge_camp(life, camp, for_founding=False): #This is kinda complicated so I'll do my best to describe what's happening. #The ALife keeps track of chunks it's aware of, which we'll use when #calculating how much of a camp we know about (value between 0..1) #First we score the camp based on what we DO know, which is pretty cut and dry: # #We consider: # How big the camp is vs. how many people we think we're going to need to fit in it (not a factor ATM) # A big camp won't be attractive to just one ALife, but a faction will love the idea of having a larger base # Distance from other camps # Certain ALife will prefer isolation # #After scoring this camp, we simply multiply by the percentage of the camp #that is known. This will encourage ALife to discover a camp first before #moving in. #In addition to all that, we want to prevent returning camps that are too close #to other camps. This is hardcoded (can't think of a reason why the ALife would want this) if for_founding: for _known_camp in [c['reference'] for c in life['known_camps'].values()]: for _pos1 in _known_camp: pos1 = [int(i) for i in _pos1.split(',')] for _pos2 in camp: pos2 = [int(i) for i in _pos2.split(',')] _dist = bad_numbers.distance(pos1, pos2) / WORLD_INFO['chunk_size'] if _dist <= 15: return 0 _known_chunks_of_camp = references.get_known_chunks_in_reference(life, camp) _current_population = 0 _current_trust = 0 for _target in life['know'].values(): if not references.is_in_reference(_target['last_seen_at'], camp): continue _current_population += 1 if can_trust(life, _target['life']['id']): _current_trust += _target['trust'] else: _current_trust -= _target['danger'] _percent_known = len(_known_chunks_of_camp)/float(len(camp)) _score = _current_trust _camp = camps.get_camp_via_reference(camp) if _camp: _score += judge_group(life, camps.get_controlling_group(_camp)) if stats.desires_to_create_camp(life): _score += len(groups.get_group(life, life['group'])['members'])/2<=len(_known_chunks_of_camp) #TODO: Why does this cause a crash? #return int(round(_percent_known*10)) #print 'camp score:',(len(camp)*_percent_known),_score,(len(camp)*_percent_known)*_score return (len(camp)*_percent_known)*_score
def position_is_in_camp(position, camp_id): return references.is_in_reference(position, get_camp(camp_id)['reference'])
def is_in_any_camp(position): for camp in WORLD_INFO['camps'].values(): if references.is_in_reference(position, camp['reference']): return camp['id'] return False