Ejemplo n.º 1
0
ObjList LifeForm::perceive(double rad){
    
    if (rad>100) rad=100;
    if (rad<2) rad=2;
//    int i=0;
//    assert(i==1);
//    
    update_position();
    
    
    SmartPointer<LifeForm> self = SmartPointer<LifeForm>(this);
//    cout<<this->species_name();
//    cout<<"in perceive"<<endl;
    std::vector<SmartPointer<LifeForm>> vector =  space.nearby(this->position(), rad);
    auto b = vector.begin();
    auto e = vector.end();
    ObjList info;// = vector
    while (b!=e) {
        auto in = this->info_about_them(*b);
        info.push_back(in);
        b++;
    }
    
    //energy cost
    energy-=perceive_cost(rad);
    if (energy<min_energy) {
        self->die();
    }
    return info;
};
Ejemplo n.º 2
0
ObjList LifeForm::perceive(double dist) {
	//cout << "perceive" << endl;
	ObjList objlist;
	if (!is_alive) return objlist;
	if (dist < min_perceive_range) dist = min_perceive_range;
	if (dist > max_perceive_range) dist = max_perceive_range;
	energy -= perceive_cost(dist);
	if (energy < min_energy) {
		die();
		return objlist;
	}
	std::vector<SmartPointer<LifeForm>> observed_objs = space.nearby(pos,dist);
	for (int i = 0; i < observed_objs.size(); i++)
		objlist.push_back(info_about_them(observed_objs[i]));
	return objlist;
}