Esempio n. 1
0
def act(player_name,agent_position,agent_arguments,agent_energy,agent_loaded,agents_viewed,plants_viewed,energy_map,world_width,world_height):
    ennemies = [agent[1] for agent in agents_viewed if agent[0]!=player_name and neighbor(agent_position,agent[1])<2]
    if ennemies:
        return ccells.attack(*ennemies[0])

    if agent_arguments and agent_arguments[0]==1:
        plants = [plant for plant in plants_viewed if neighbor(agent_position,plant[0])<2]
        if plants:
            plant_position = plants[0][0]
            plant_eff      = plants[0][1]

            occupied = False
            for agent_viewed in agents_viewed:
                if agent_viewed[1]==plant_position:
                    occupied = True
            if occupied:
                return ccells.moveTo(agent_arguments[1],agent_arguments[2])

            #print "found plant"
            #print plant_position,agent_position
            #print occupied
            if agent_energy>55:
                return ccells.spawn(plant_position[0],plant_position[1])
            else:
                return ccells.eat()
        return ccells.moveTo(agent_arguments[1],agent_arguments[2])
    else:
        if agent_energy>70:
            destx = random.randint(0,world_width-1)
            desty = random.randint(0,world_height-1)
            return ccells.spawn(destx,desty,[1,destx,desty,agent_position[0],agent_position[1]])
        else:
            return ccells.eat()
Esempio n. 2
0
def Action(type,pos=None):
    if type==ACT_EAT: return ccells.eat()
    elif type==ACT_LIFT: return ccells.lift()
    elif type==ACT_DROP: return ccells.drop()
    elif type==ACT_SPAWN: return ccells.spawn(pos[0],pos[1],list(pos))
    elif type==ACT_MOVE: return ccells.moveTo(*pos)
    elif type==ACT_ATTACK: return ccells.attack(*pos)
    else: assert(False)
Esempio n. 3
0
def act(player_name,agent_position,agent_arguments,agent_energy,agent_loaded,agents_viewed,plants_viewed,energy_map,world_width,world_height):
    global prout
    print "player_name=",player_name
    print "agent_position =",agent_position
    print "agent_arguments =",agent_arguments
    print "agent_energy =",agent_energy,"agent_loaded =",agent_loaded
    print "agents_viewed =",agents_viewed
    print "plants_viewed =",plants_viewed
    print "world_size =",(world_width,world_height)
    print "energy_map =",len(energy_map)
    print ccells.__doc__
    prout += 1
    print "prout =",prout
    print "messages =",ccells.getMessages()
    ret = ccells.doNothing()
    ret = ccells.spawn(10,10,[23,42])
    ret = ccells.moveTo(10,14)
    ret = ccells.eat()
    ret = ccells.attack(10,23)
    ret = ccells.lift()
    ret = ccells.drop()
    print ret
    ccells.sendMessage("hello from prout = %d" % prout)
    return ret