本文整理汇总了C++中Bird::getSpeed方法的典型用法代码示例。如果您正苦于以下问题:C++ Bird::getSpeed方法的具体用法?C++ Bird::getSpeed怎么用?C++ Bird::getSpeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bird
的用法示例。
在下文中一共展示了Bird::getSpeed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: step
void BirdModel::step() {
//std::cout << " " << rank << " " << std::endl;
std::vector<int> position(2);
for (int i = 0; i < dimX * dimY; i++) {
repast::AgentId id = repast::AgentId(i, rank, 0);
if (grid->getLocation(id, position)) {
Bird* thisBird = agents.getAgent(id);
Bird* neighbour;
bool isFastest = true;
neighbour = grid->getObjectAt(
repast::Point<int>(position[0], (position[1] + 1) % sizeY));
isFastest *= (neighbour->getSpeed() < thisBird->getSpeed());
neighbour = grid->getObjectAt(
repast::Point<int>((position[0] + 1) % sizeX, position[1]));
isFastest *= (neighbour->getSpeed() < thisBird->getSpeed());
neighbour = grid->getObjectAt(
repast::Point<int>(position[0], (position[1] - 1 + sizeY) % sizeY));
isFastest *= (neighbour->getSpeed() < thisBird->getSpeed());
neighbour = grid->getObjectAt(
repast::Point<int>((position[0] - 1 + sizeX) % sizeX, position[1]));
isFastest *= (neighbour->getSpeed() < thisBird->getSpeed());
thisBird->setFastest(isFastest);
// If bird is fastest it will decrease its speed, otherwise will try to gain speed (speed += 0.0 | 0.5 | 1.0)
if (isFastest)
thisBird->setSpeed(thisBird->getSpeed() -0.75);
else
thisBird->setSpeed(thisBird->getSpeed() + (std::rand()%3)*0.5);
/*
Bird* bird_0 = agents.getAgent(id);
Bird* bird_1;
if (position[1] != sizeY - 1) // Check if agent is not in the lowest row
bird_1 = grid->getObjectAt(
repast::Point<int>(position[0], position[1] + 1));
else if (position[0] != sizeX - 1) // Check if agent is in the last column
bird_1 = grid->getObjectAt(
repast::Point<int>(position[0] + 1, 0));
else
// agent is in (sizeX-1 ; sizeY-1)
bird_1 = grid->getObjectAt(repast::Point<int>(0, 0));
std::cout << "THIS: " << bird_0->getId() << " NEXT: "
<< bird_1->getId() << std::endl;
*/
}
}
}