예제 #1
0
bool Ant::move(Ground& ground)
{
  --time;
  //first fight
  std::list<Ant*> ants_near = ground.findAntsNextTo(x, y, id);
  if (!ants_near.empty())
  {
    return fight(ants_near.front());
  }
  if (move_function == nullptr) //ant just go out nest
  {
    move_function = &Ant::freeMove;
  }
  else if (food == can_carry_food) //and is going to nest, no matter what happen
  {
    move_function = &Ant::goToNest;
  }
  else if (food != can_carry_food && ground.isFood(x, y)) //on food field
  {
    move_function = &Ant::getFood;
  }
  else if (time < 0) //out of stamina ;] 
  {
    move_function = &Ant::goToNest;
    make_path = false;
  }
  else if (ground.isSmell(x, y, id)) //smell
  {
    move_function = &Ant::followSmell;
  }
  (this->*move_function)(ground);

  last_x = x;
  last_y = y;

  if (x == nest_x && y == nest_y) //going into nest
  {
    move_function = nullptr;
    time_in_nest = nest_time_distribution(*gen);
    return false;
  }
  return true;
}
예제 #2
0
void Ant::getFood(Ground& ground)
{
  food += ground.getFoodFromField(x, y, can_carry_food - food);
  make_path = ground.isFood(x, y);
  move_function = &Ant::goToNest;
}