本文整理汇总了C++中Food::getRadius方法的典型用法代码示例。如果您正苦于以下问题:C++ Food::getRadius方法的具体用法?C++ Food::getRadius怎么用?C++ Food::getRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Food
的用法示例。
在下文中一共展示了Food::getRadius方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
/// ------------------------------------------------------------------------------------------------
void World::update()
{
if (tick_cnt++ <= Param::n_ticks)
{
Food* pfood;
for (auto fi : fishes_)
{
fi->update(foods_);
pfood = foods_.at(fi->getClosestFood());
if (Vec2DLength(fi->getPosition() - pfood->getPosition())
< (pfood->getRadius() + fi->getRadius()))
{
fi->incrementFood(Param::n_food - foods_.size());
foods_.erase(foods_.begin() + fi->getClosestFood());
// foods_.push_back(new Food());
if (foods_.empty())
{
cerr << "No more foods" << endl;
foods_.push_back(new Food());
}
}
}
/// Highlight best fish
RGBA rgba =
{ 0, 0, 0, 255 };
fish_best_->setRGBA(rgba);
for (uint16_t i = 0; i < fishes_.size(); i++)
{
if (fishes_.at(i)->getFitness() > fish_best_->getFitness())
{
fish_best_ = fishes_.at(i);
}
}
rgba =
{ 255,0,0,255};
fish_best_->setRGBA(rgba);
}
else
{
/// Resupply food
for (uint16_t i = foods_.size(); i < Param::n_food; i++)
{
foods_.push_back(new Food());
}
cout << "Next Generation: " << gen_algo_->getGenerationCount() << endl;
tick_cnt = 0;
/// Update chromosomes fitness
vector<Chromosome> pop = gen_algo_->getPopulation();
for (uint16_t i = 0; i < fishes_.size(); i++)
{
pop[i].setFitness(fishes_.at(i)->getFitness());
}
/// Run Genetic Algorithm
pop = gen_algo_->NextGeneration(pop);
/// Update Fishes' brain with new values
for (uint16_t i = 0; i < fishes_.size(); i++)
{
fishes_[i]->putWeights(pop[i].getGenes());
fishes_[i]->reset();
}
cout << "Average Fitness: " << gen_algo_->getAverageFitness() << endl;
cout << "Best Fitness: " << gen_algo_->getBestFitness() << endl << endl;
}
}