本文整理汇总了C++中Environment::addObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Environment::addObject方法的具体用法?C++ Environment::addObject怎么用?C++ Environment::addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::addObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void)
{
/**
* Unit tests for environment
*/
try
{
SimpleSP spa;
Coordonate<2,int> coord;
// Test for addObject()
// Add some resources
Environment<2, int, int> env;
std::vector<AResource*> res;
for(unsigned i = 0; i < 5; i++)
{
coord[0] = i;
coord[1] = 1;
res.push_back(new Resource<2,int,int>(coord, 100, false, spa));
}
env.addObject(res);
if(env.getResources() != res)
throw std::runtime_error("Error in expectations for first test");
// Add some taskSpots
Task t;
StepConstraint sc(0, t, ConstraintComp::GREATER, 500);
ConstraintSystem constraintSystem;
constraintSystem.push(&sc);
std::vector<ATaskSpot*> ts;
for(unsigned i = 0; i < 5; i++)
{
coord[0] = i;
coord[1] = 4;
ts.push_back(new TaskSpot<2,int>(coord, std::ref(t), [](int& i, double _time){ return i+0.001*_time; }));
}
env.addObject(ts);
if(env.getTaskSpots() != ts)
throw std::runtime_error("Error in expectations for second test");
// Test for update()
env.update(0);
env.update(-10);
env.update(10);
// Test for _dump()
env.dump();
}
catch(exception& e)
{
logger(Logger::ERROR) << e.what();
logger << "FATAL ERROR - EXIT NOW !";
}
return 0;
}
示例2: main
int main() {
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Main");
// Setup test creature
Creature creature = Creature();
creature.position[0] = 100;
creature.position[1] = 100;
// creature.velocity[0] = 20;
// creature.velocity[1] = 20;
creature.setRotation(50);
env.addObject(&creature);
// Setup creatures
for (int i = 0; i < NUM_CREATURES; ++i) {
creatures[i] = Creature();
creatures[i].position[0] = 50 * (i + 1);
creatures[i].position[1] = 50 * (i + 1);
creatures[i].setRotation(0);
env.addObject(&creatures[i]);
}
// Setup food
for (int i = 0; i < NUM_FOOD; ++i) {
Food f = Food();
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
//.........这里部分代码省略.........