示例#1
0
def warrior_around(l_cells_warriors):
    """
        Returns True if there is a warrior next to thr walker,
        False otherwise.
    """
    around = False
    for elem in l_cells_warriors:
        if len(c.get_present_agent(
                elem)) == a.AGENT_MAX_IDX + 1 and a.agent_is_warrior(
                    c.get_present_agent(elem)):
            around = True
    return around
示例#2
0
def add_cell_in_places(env, env_size, l, l_pos, i, j):
    """
        Adds two different elements to two different lists. The first one is
        composed by the cells containing potential places and the second one
        contains the positions of this cells in the environment.
    """
    cell = e.get_cell(env, (i % env_size, j % env_size))
    if c.get_present_agent(cell) != None and len(
            c.get_present_agent(cell)) == a.AGENT_MAX_IDX + 1:
        l.append(cell)
        l_pos.append((i % env_size, j % env_size))
    return l, l_pos
示例#3
0
def average_living(pop,cell_refs):
	""" 
		cherche le niveau de vie moyen des agents situé dans un bloc de coté 6 (zone*2) centré dans la cellule cible 
	"""
	x,y = cell_refs
	zone = 3
	cells_average_list = []
	sugar_level_sum = 0
	agents_in_zone_of_cell = 0
	env = p.get_env(pop)
	pos_start_calc = correct_position((x-zone,y+zone),env)
	xi,yi = pos_start_calc
	i = 0
	j = -2*zone
	for j in range(-2*zone,0,1):
		for i in range(0,2*zone):
			if i!=j:
				cell = e.get_cell(env,correct_position((xi+i,yi+j),env))
				if c.agent_is_present(cell):
					agents_in_zone_of_cell +=1
					sugar_level_sum += get_sugar_level(c.get_present_agent(cell))
	if agents_in_zone_of_cell != 0:
		average = sugar_level_sum/agents_in_zone_of_cell
	else:
		average = 0
	return average
示例#4
0
def average_living(pop, cell_refs):
    """ 
		cherche le niveau de vie moyen des agents situé dans un bloc de coté 6 (zone*2) centré dans la cellule cible 
	"""
    x, y = cell_refs
    zone = 3
    cells_average_list = []
    sugar_level_sum = 0
    agents_in_zone_of_cell = 0
    env = p.get_env(pop)
    pos_start_calc = correct_position((x - zone, y + zone), env)
    xi, yi = pos_start_calc
    i = 0
    j = -2 * zone
    for j in range(-2 * zone, 0, 1):
        for i in range(0, 2 * zone):
            if i != j:
                cell = e.get_cell(env, correct_position((xi + i, yi + j), env))
                if c.agent_is_present(cell):
                    agents_in_zone_of_cell += 1
                    sugar_level_sum += get_sugar_level(
                        c.get_present_agent(cell))
    if agents_in_zone_of_cell != 0:
        average = sugar_level_sum / agents_in_zone_of_cell
    else:
        average = 0
    return average
示例#5
0
def try_to_move(walker, pos, env, env_size):
    """
        Makes the walker move if he doesn't meet agents.
    """
    positions = []
    x, y = get_pos(walker)
    list_arounds = [((x + 1) % env_size, y), ((x - 1) % env_size, y),
                    (x, (y + 1) % env_size), (x, (y - 1) % env_size)]
    for elem in list_arounds:
        cell = e.get_cell(env, elem)
        if c.get_present_agent(cell) == None or c.get_present_agent(
                cell) == "alerte":
            positions.append(elem)
    if len(positions) > 0:
        pos = positions[randrange(len(positions))]
    else:
        pos = get_pos(walker)
    return pos
示例#6
0
def is_interested_to_move(agent,target):
	"""
		- vérifier si le total_gain(agent,target) est plus grand que zèro 
		- si un autre agent peut atteindre la cellule avant lui
		- si il n'y a pas d'agents dans la direction choisie 
	"""
	pos = get_pos(agent)
	xd,yd = u.vector_diff(pos,target)
	env = get_env(agent)
	agent_on_way = False
	if xd == 0:
		step  = (1 if yd < 0 else -1)
		next_move = correct_position((pos[0],pos[1]+step),env)
		agent_on_way = c.get_present_agent(e.get_cell(env,next_move))
	else:
		step  = (1 if xd < 0 else -1)
		next_move = correct_position((pos[0]+step,pos[1]),env)
		agent_on_way = c.get_present_agent(e.get_cell(env,next_move))
	return (not is_an_agent_can_be_there_faster(agent,target) and not agent_on_way and total_gain(agent,target) > 0)
示例#7
0
def theres_is_an_other_sex_around(agent):
	"""
		évaluer la présence d’un potentiel (dans le sens ou il peut se reproduire avec) agent à proximité
	"""
	vision = 1
	x,y = get_pos(agent)
	agent_sex = get_sex(agent)
	env = get_env(agent)
	already_found = False
	i = -vision
	while i <= vision and not already_found:
		if i !=0:
			cell_x = e.get_cell(env,correct_position((x,y+vision),env))
			cell_y = e.get_cell(env,correct_position((x+vision,y),env))
			if c.agent_is_present(cell_x):
				already_found = (get_sex(c.get_present_agent(cell_x)) != agent_sex)
			if c.agent_is_present(cell_y):
				already_found = (get_sex(c.get_present_agent(cell_y)) != agent_sex)
		i+=1
	return already_found
示例#8
0
def possible_cell_position(env, walker, pos):
    """
        Returns the position where the walker will have to go
        if there is no agent in the cell the position belongs to.
    """
    if not c.agent_is_present(e.get_cell(env, pos)) or c.get_present_agent(
            e.get_cell(env, pos)) == "alerte":
        pos_cell = pos
    else:
        pos_cell = get_pos(walker)
    return pos_cell
示例#9
0
def is_interested_to_move(agent, target):
    """
		- vérifier si le total_gain(agent,target) est plus grand que zèro 
		- si un autre agent peut atteindre la cellule avant lui
		- si il n'y a pas d'agents dans la direction choisie 
	"""
    pos = get_pos(agent)
    xd, yd = u.vector_diff(pos, target)
    env = get_env(agent)
    agent_on_way = False
    if xd == 0:
        step = (1 if yd < 0 else -1)
        next_move = correct_position((pos[0], pos[1] + step), env)
        agent_on_way = c.get_present_agent(e.get_cell(env, next_move))
    else:
        step = (1 if xd < 0 else -1)
        next_move = correct_position((pos[0] + step, pos[1]), env)
        agent_on_way = c.get_present_agent(e.get_cell(env, next_move))
    return (not is_an_agent_can_be_there_faster(agent, target)
            and not agent_on_way and total_gain(agent, target) > 0)
示例#10
0
def average_around_agents_sugar_level(env, l_good_pos):
    """
        Returns a list containing list containing the average of the
        sugar level of the agents around the cells where the agent can
        go.
    """
    vision = 3
    l_average_res = []
    for pos in l_good_pos:
        x, y = pos
        tot_list = []
        for i in range(x - vision, x + vision + 1):
            for j in range(y - vision, y + vision + 1):
                cell = e.get_cell(env, (i, j))
                if (i, j) != (x, y) and c.agent_is_present(cell) and len(
                        c.get_present_agent(cell)) == AGENT_MAX_IDX + 1:
                    agent = c.get_present_agent(cell)
                    tot_list.append(get_sugar_level(agent))
        add_average_sugar_level(tot_list, l_average_res)
    return l_average_res
示例#11
0
def theres_is_an_other_sex_around(agent):
    """
		évaluer la présence d’un potentiel (dans le sens ou il peut se reproduire avec) agent à proximité
	"""
    vision = 1
    x, y = get_pos(agent)
    agent_sex = get_sex(agent)
    env = get_env(agent)
    already_found = False
    i = -vision
    while i <= vision and not already_found:
        if i != 0:
            cell_x = e.get_cell(env, correct_position((x, y + vision), env))
            cell_y = e.get_cell(env, correct_position((x + vision, y), env))
            if c.agent_is_present(cell_x):
                already_found = (get_sex(c.get_present_agent(cell_x)) !=
                                 agent_sex)
            if c.agent_is_present(cell_y):
                already_found = (get_sex(c.get_present_agent(cell_y)) !=
                                 agent_sex)
        i += 1
    return already_found
示例#12
0
def possible_cell_position(env, agent, pos):
    """
        Returns a tuple of two int containing the next position of
        an agent.
    """
    if c.get_present_agent(e.get_cell(
            env, pos)) == "alerte" and agent_is_warrior(agent):
        pos_cell = pos
    elif not c.agent_is_present(e.get_cell(env, pos)):
        pos_cell = pos
    else:
        pos_cell = get_pos(agent)
    return pos_cell
示例#13
0
def put_aura(pop, walker):
    """
        Puts the aura of the walker on the environnement.
    """
    vision = get_vision(walker) - 2  # aura radius = vision radius -2
    env = p.get_env(pop)
    env_size = e.size(env)
    x, y = get_pos(walker)
    for i in range(x - vision, x + vision + 1):
        for j in range(y - vision, y + vision + 1):
            if (i, j) != (x, y):
                cell = e.get_cell(env, (i, j))
                if c.get_present_agent(cell) == None:
                    c.set_present_agent(cell, "alerte")
示例#14
0
def add_cell_in_places(agent, env, env_size, l, l_pos, i, j):
    """
        Adds two different elements to two different lists. The first one is
        composed by the cells containing potential places and the second one
        contains the positions of this cells in the environment.
    """
    cell = e.get_cell(env, (i % env_size, j % env_size))
    if agent_is_warrior(agent) and c.get_present_agent(cell) == "alerte":
        l.append(cell)
        l_pos.append((i % env_size, j % env_size))
    if not c.agent_is_present(cell):
        l.append(cell)
        l_pos.append((i % env_size, j % env_size))
    return l, l_pos
示例#15
0
def take_aura(pop, walker):
    """
        Makes the aura of the walker disappear from the environnement.
    """
    vision = get_vision(walker) - 1
    env = p.get_env(pop)
    env_size = e.size(env)
    x, y = get_pos(walker)
    for i in range(x - vision, x + vision + 1):
        for j in range(y - vision, y + vision + 1):
            if (i, j) != (x, y):
                cell = e.get_cell(env, (i, j))
                if c.get_present_agent(cell) == "alerte":
                    c.set_present_agent(cell, None)
示例#16
0
def partners_list_under_conditions(env, agent, l_pos):
    """
        Returns the partner list of a female agent.
        This list must consider the conditions of age
        and sex of the agent and her partner.
    """
    l_partners = []
    for pos in l_pos:
        cell = e.get_cell(env, pos)
        partner = c.get_present_agent(cell)
        if len(partner) == AGENT_MAX_IDX +1 and get_sex(agent) == 0 and get_sex(agent) != get_sex(partner)\
           and get_age(agent) > 20 and get_age(partner) > 20 and get_sugar_level(agent) > 10\
           and get_sugar_level(partner):
            l_partners.append(partner)
    return l_partners
def friend_need(env, agent, target):
    """
        Regarde dans la vision de l'agent si d'autres agent on besoin du sucre dans la cible.
    """
    cells_refs = a.get_cells_refs( env, agent )    
    # On parcourt les cellules en vision, voir si des agents sont dans le besoin
    for cell_ref in cells_refs:
        cell = get_cell(env, cell_ref)
        if c.agent_is_present( cell ):
            agent = c.get_present_agent(cell)
            if a.get_sugar_level(agent) < a.get_metabolism(agent) and a.is_in_vision(agent, env, target):
                return True

    return False
    
        
############################################################################
示例#18
0
def walker_around_check(pop, agent):
    """
        Returns the list of the contamined cells around the agent.
    """
    walker_around = False
    l_around = []
    env = p.get_env(pop)
    x, y = get_pos(agent)
    all_x = range(x - 1, x + 2)
    all_y = range(y - 1, y + 2)
    for i in all_x:
        for j in all_y:
            cell = e.get_cell(env, (i, j))
            l_around.append(c.get_present_agent(cell))
    for elem in l_around:
        if elem != None and len(elem) == w.WALKER_MAX_IDX + 1:
            walker_around = True
    return walker_around