本文整理汇总了C++中ObjList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjList::size方法的具体用法?C++ ObjList::size怎么用?C++ ObjList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjList
的用法示例。
在下文中一共展示了ObjList::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
double byf69::average_bearing(ObjList nearby) {
double sum = 0;
for (ObjList::iterator i = nearby.begin(); i != nearby.end(); i++) {
sum += i->bearing;
}
return sum / nearby.size();
}
示例2: sqrt
void amw3647::hunt(void) {
const String fav_food = "Algae";
hunt_event = Nil<Event>();
if (health() == 0) { return; }
update_pos();
double region = sqrt(10 / density);
bound(region, grid_max * 0.01, grid_max * 0.1);
ObjList prey = perceive(region);
density = (prey.size() + 0.01) / (region * region);
double best_d = HUGE;
double best_me = HUGE;
double best_me_bearing = 0;
double old_speed = get_speed();
for (ObjInfo i : prey) {
if (i.species == species_name()) {
if (best_me > i.distance) {
best_me = i.distance;
best_me_bearing = i.bearing;
}
} else if (i.species == fav_food) {
if (best_d > i.distance) {
set_speed(old_speed * 1.01);
set_course(i.bearing);
best_d = i.distance;
course_changed = 0;
}
} else if (victory(i)) {
if (best_d * 0.1 > i.distance) {
switch (encounter_strategy) {
case FASTER_GUY_WINS:
set_speed(i.their_speed + M_E);
break;
case SLOWER_GUY_WINS:
set_speed(i.their_speed - M_E);
break;
default:
set_speed((i.their_speed + 0.01) * 1.01);
break;
}
set_course(i.bearing);
best_d = i.distance;
course_changed = 0;
}
}
}
if (best_d == HUGE) {
if(course_changed == 0) {
course_changed = 1;
if (best_me == HUGE) {
set_course(get_course() + drand48() * 0.25 * M_PI);
set_speed((1 - drand48() * 0.05) * old_speed);
} else {
set_course(best_me_bearing);
}
}
}
if (p.distance(Point(0, 0)) > (grid_max / 3)) {
if(course_changed == 0) {
course_changed = 1;
set_course(p.bearing(Point(0, 0)));
set_speed(old_speed * 0.90);
}
}
SmartPointer<amw3647> self{this};
hunt_event = new Event(10.0, [self] (void) { self->hunt();});
if (health() >= 3.0) spawn();
}