本文整理汇总了C++中Mutator::mutate方法的典型用法代码示例。如果您正苦于以下问题:C++ Mutator::mutate方法的具体用法?C++ Mutator::mutate怎么用?C++ Mutator::mutate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mutator
的用法示例。
在下文中一共展示了Mutator::mutate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
f.reset(WIDTH, HEIGHT);
food.push_back(f);
}
sf::Clock frame_clock;
sf::Clock gen_clock;
int frame_count = 0;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::W) {
creature.moveForward();
} else if (event.key.code == sf::Keyboard::S) {
printf("%s\n", "S PRESSED");
} else if (event.key.code == sf::Keyboard::A) {
creature.setRotation(creature.getRotation() + 5);
} else if (event.key.code == sf::Keyboard::D) {
creature.setRotation(creature.getRotation() - 5);
} else if (event.key.code == sf::Keyboard::P) {
launchConsole();
frame_clock.restart();
}
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Right) {
sf::Vector2f position = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));
}
break;
default:
break;
}
}
window.clear();
for (int i = 0; i < NUM_FOOD; ++i) {
if (!food[i].isConsumed()) window.draw(food[i]);
}
// Debug creature
creature.draw(&window);
for (int i = 0; i < NUM_FOOD; ++i) {
if (creature.isPointInFOV(food[i].getPosition())) {
// printf("%f\n", creature.distanceToPoint(food[i].getPosition()));
}
}
for (int i = 0; i < NUM_CREATURES; ++i) {
creatures[i].process(&food);
creatures[i].draw(&window);
}
// Handle generations
if (gen_clock.getElapsedTime().asSeconds() > GENERATION_LENGTH_SECONDS) {
std::cout << "Generation: " << ++gen_count << std::endl;
writeOutData();
// Reset food
for (int i = 0; i < NUM_FOOD; ++i) {
food[i].reset(WIDTH, HEIGHT);
}
// Sort by energy level
std::sort(creatures, creatures + NUM_CREATURES, compareCreatures);
// Select and mutate the top 50% of creatures
Mutator mutator = Mutator();
for (int i = 0; i < NUM_CREATURES/2; ++i) {
printf("Creature %d %f\n", i, creatures[i].getEnergy());
mutator.setTarget(&creatures[i]);
creatures[i].resetEnergy();
creatures[i].position[0] = WIDTH / 2;
creatures[i].position[1] = HEIGHT / 2;
mutator.mutate(&creatures[NUM_CREATURES - 1 - i]);
creatures[NUM_CREATURES - 1 - i].resetEnergy();
creatures[NUM_CREATURES - 1 - i].position[0] = WIDTH / 2;
creatures[NUM_CREATURES - 1 - i].position[1] = HEIGHT / 2;
}
gen_clock.restart();
}
window.display();
sf::Time elapsed = frame_clock.restart();
env.step(elapsed.asSeconds());
}
return 0;
}