Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def tick(life):
	if not 'shelter' in life['state_flags']:
		life['state_flags']['shelter'] = judgement.get_best_shelter(life)
	
	if not life['state_flags']['shelter'] in life['known_chunks']:
		judgement.judge_chunk(life, life['state_flags']['shelter'])
	
	if not chunks.get_flag(life, life['state_flags']['shelter'], 'shelter_cover'):
		return False
	
	if not list(life['pos'][:2]) in chunks.get_flag(life, life['state_flags']['shelter'], 'shelter_cover'):
		if not lfe.path_dest(life) or (not chunks.position_is_in_chunk(lfe.path_dest(life), life['state_flags']['shelter'])):
			_cover = chunks.get_flag(life, life['state_flags']['shelter'], 'shelter_cover')
			lfe.walk_to(life, random.choice(_cover))
Beispiel #4
0
def judge_chunk_life(life, chunk_id):
	if lfe.ticker(life, 'judge_chunk_life_tick', 30):
		return False
	
	_score = 0
	for life_id in life['known_chunks'][chunk_id]['life']:
		_target = brain.knows_alife_by_id(life, life_id)
		_is_here = False
		_actually_here = False
		
		if not _target['last_seen_at'] or not chunks.position_is_in_chunk(_target['last_seen_at'], chunk_id) and not _target['life']['path']:
			continue
	
	return _score 
Beispiel #5
0
def judge_chunk_life(life, chunk_id):
    if lfe.ticker(life, "judge_chunk_life_tick", 30):
        return False

    _score = 0
    for life_id in life["known_chunks"][chunk_id]["life"]:
        _target = brain.knows_alife_by_id(life, life_id)
        _is_here = False
        _actually_here = False

        if (
            not _target["last_seen_at"]
            or not chunks.position_is_in_chunk(_target["last_seen_at"], chunk_id)
            and not _target["life"]["path"]
        ):
            continue

    return _score
Beispiel #6
0
def tick(life):
    if not 'shelter' in life['state_flags']:
        life['state_flags']['shelter'] = judgement.get_best_shelter(life)

    if not life['state_flags']['shelter'] in life['known_chunks']:
        judgement.judge_chunk(life, life['state_flags']['shelter'])

    if not chunks.get_flag(life, life['state_flags']['shelter'],
                           'shelter_cover'):
        return False

    if not list(life['pos'][:2]) in chunks.get_flag(
            life, life['state_flags']['shelter'], 'shelter_cover'):
        if not lfe.path_dest(life) or (not chunks.position_is_in_chunk(
                lfe.path_dest(life), life['state_flags']['shelter'])):
            _cover = chunks.get_flag(life, life['state_flags']['shelter'],
                                     'shelter_cover')
            lfe.walk_to(life, random.choice(_cover))
Beispiel #7
0
def is_in_reference(position, reference):
    for chunk_key in reference:
        if chunks.position_is_in_chunk(position, chunk_key):
            return True

    return False
Beispiel #8
0
def judge_chunk(life, chunk_id, visited=False, seen=False, checked=True, investigate=False):
    if lfe.ticker(life, "judge_tick", 30):
        return False

    chunk = maps.get_chunk(chunk_id)
    _score = 0

    if not chunk_id in life["known_chunks"]:
        life["known_chunks"][chunk_id] = {
            "last_visited": -1,
            "last_seen": -1,
            "last_checked": -1,
            "discovered_at": WORLD_INFO["ticks"],
            "flags": {},
            "life": [],
        }

    _camp = chunks.get_global_flag(chunk_id, "camp")
    if _camp and not _camp in life["known_camps"]:
        camps.discover_camp(life, _camp)

    _known_chunk = life["known_chunks"][chunk_id]

    if seen:
        _known_chunk["last_seen"] = WORLD_INFO["ticks"]

    if visited:
        _known_chunk["last_visited"] = WORLD_INFO["ticks"]
        _known_chunk["last_seen"] = WORLD_INFO["ticks"]

    if checked:
        _known_chunk["last_checked"] = WORLD_INFO["ticks"]

    _trusted = 0
    for _target in life["know"].values():
        if not _target["last_seen_at"]:
            continue

        _is_here = False
        _actually_here = False

        if chunks.position_is_in_chunk(_target["last_seen_at"], chunk_id) and not _target["life"]["path"]:
            _is_here = True
        elif (
            not _target["last_seen_time"]
            and _target["life"]["path"]
            and chunks.position_is_in_chunk(lfe.path_dest(_target["life"]), chunk_id)
        ):
            _is_here = True

        if chunks.position_is_in_chunk(_target["life"]["pos"], chunk_id):
            _actually_here = True

        if _is_here:
            if not _target["life"]["id"] in _known_chunk["life"]:
                _known_chunk["life"].append(_target["life"]["id"])

            if is_target_dangerous(life, _target["life"]["id"]):
                _score -= 10
            elif life["group"] and groups.is_leader(life, life["group"], _target["life"]["id"]):
                _trusted += _target["trust"]
        else:
            if _target["life"]["id"] in _known_chunk["life"]:
                _known_chunk["life"].remove(_target["life"]["id"])

    if investigate and not visited:
        chunks.flag(life, chunk_id, "investigate", True)
    elif visited and chunks.get_flag(life, chunk_id, "investigate"):
        chunks.unflag(life, chunk_id, "investigate")

    if chunks.get_flag(life, chunk_id, "investigate"):
        _score += 5

        # for camp in life['known_camps']:
        # 	if not chunk_id in camps.get_camp(camp)['reference']:
        # 		continue

        # if not life['camp'] == camp['id']:
        # 	continue

        # if stats.desires_shelter(life):
        # 	_score += judge_camp(life, life['camp'])

    if lfe.execute_raw(life, "discover", "remember_shelter"):
        judge_shelter(life, chunk_id)

        # if stats.desires_interaction(life):
        # 	_score += _trusted

    if seen:
        pass
        # TODO: Still a good idea... maybe use for shelter?
        # for item in chunk['items']:
        # 	_item = brain.remember_known_item(life, item)
        # 	if _item:
        # 		_score += _item['score']

    life["known_chunks"][chunk_id]["score"] = _score

    return _score
Beispiel #9
0
def judge_chunk(life, chunk_id, visited=False, seen=False, checked=True, investigate=False):
	if lfe.ticker(life, 'judge_tick', 30):
		return False
	
	chunk = maps.get_chunk(chunk_id)
	_score = 0
	
	if not chunk_id in life['known_chunks']:
		life['known_chunks'][chunk_id] = {'last_visited': -1,
			'last_seen': -1,
			'last_checked': -1,
			'discovered_at': WORLD_INFO['ticks'],
			'flags': {},
			'life': []}
	
	_camp = chunks.get_global_flag(chunk_id, 'camp')
	if _camp and not _camp in life['known_camps']:
		camps.discover_camp(life, _camp)
	
	_known_chunk = life['known_chunks'][chunk_id]	
	
	if seen:
		_known_chunk['last_seen'] = WORLD_INFO['ticks']
	
	if visited:
		_known_chunk['last_visited'] = WORLD_INFO['ticks']
		_known_chunk['last_seen'] = WORLD_INFO['ticks']
	
	if checked:
		_known_chunk['last_checked'] = WORLD_INFO['ticks']
	
	_trusted = 0
	for _target in life['know'].values():
		if not _target['last_seen_at']:
			continue
		
		_is_here = False
		_actually_here = False
		
		if chunks.position_is_in_chunk(_target['last_seen_at'], chunk_id) and not _target['life']['path']:
			_is_here = True
		elif not _target['last_seen_time'] and _target['life']['path'] and chunks.position_is_in_chunk(lfe.path_dest(_target['life']), chunk_id):
			_is_here = True
		
		if chunks.position_is_in_chunk(_target['life']['pos'], chunk_id):
			_actually_here = True
			
		if _is_here:
			if not _target['life']['id'] in _known_chunk['life']:
				_known_chunk['life'].append(_target['life']['id'])
			
			if is_target_dangerous(life, _target['life']['id']):
				_score -= 10
			elif life['group'] and groups.is_leader(life, life['group'], _target['life']['id']):
				_trusted += _target['trust']
		else:
			if _target['life']['id'] in _known_chunk['life']:
				_known_chunk['life'].remove(_target['life']['id'])
	
	if investigate and not visited:
		chunks.flag(life, chunk_id, 'investigate', True)
	elif visited and chunks.get_flag(life, chunk_id, 'investigate'):
		chunks.unflag(life, chunk_id, 'investigate')
	
	if chunks.get_flag(life, chunk_id, 'investigate'):
		_score += 5
	
	#for camp in life['known_camps']:
	#	if not chunk_id in camps.get_camp(camp)['reference']:
	#		continue
		
		
		#if not life['camp'] == camp['id']:
		#	continue
	
		#if stats.desires_shelter(life):
		#	_score += judge_camp(life, life['camp'])
	
	if lfe.execute_raw(life, 'discover', 'remember_shelter'):
		judge_shelter(life, chunk_id)
	
	#if stats.desires_interaction(life):
	#	_score += _trusted
	
	if seen:
		pass
		#TODO: Still a good idea... maybe use for shelter?
		#for item in chunk['items']:
		#	_item = brain.remember_known_item(life, item)
		#	if _item:
		#		_score += _item['score']

	life['known_chunks'][chunk_id]['score'] = _score
	
	return _score
Beispiel #10
0
def is_in_reference(position, reference):
    for chunk_key in reference:
        if chunks.position_is_in_chunk(position, chunk_key):
            return True

    return False