本文整理汇总了C++中Strategy::getUtility方法的典型用法代码示例。如果您正苦于以下问题:C++ Strategy::getUtility方法的具体用法?C++ Strategy::getUtility怎么用?C++ Strategy::getUtility使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Strategy
的用法示例。
在下文中一共展示了Strategy::getUtility方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
Sensing* sensing = new Sensing();
Control* control = new Control();
ServoControl* servo = new ServoControl();
servo->setEventHandler(sensing);
Strategy* strategies [] = {
new FindSiteStrategy(sensing, control, servo), new HitButtonStrategy(sensing, control, servo),
new HalfHZDanceStrategy(sensing, control, servo), new OneHZDanceStrategy(sensing, control, servo),
new TwoHZDanceStrategy(sensing, control, servo), new FourHZDanceStrategy(sensing, control, servo),
new SixHZDanceStrategy(sensing, control, servo), new EightHZDanceStrategy(sensing, control, servo)
};
int STRATEGIES_COUNT = 8;
servo->setPosition(90);
printf("READY!\n");
int pwr = power_button_get_value();
while(pwr == power_button_get_value()) {
msleep(400);
}
timespec current;
timespec old;
clock_gettime(CLOCK_MONOTONIC, ¤t);
pwr = power_button_get_value();
Strategy* oldStrategy = 0;
while (pwr == power_button_get_value()) {
printf("-------------------------------\n");
double bestUtility = -1;
int strategyIndex = 0;
Strategy* strategy = 0;
for (int i = 0; i < STRATEGIES_COUNT; i++) {
Strategy* s = strategies[i];
double util = s->getUtility();
if (util > bestUtility) {
strategy = s;
bestUtility = util;
strategyIndex = i;
}
}
//printf("B: %d\n", sensing->getBottomDistance());
//printf("T: %d\n", sensing->getTopDistance());
old = current;
clock_gettime(CLOCK_MONOTONIC, ¤t);
double diff = (current.tv_sec - old.tv_sec) + ((current.tv_nsec - old.tv_nsec) / NANOSECONDS_PER_SECOND);
printf("T: %f, S: %d\n", diff, strategyIndex);
control->controlTick(diff);
strategy->step(diff, strategy != oldStrategy);
oldStrategy = strategy;
//double f = sensing->getFrequency();
printf("DISTANCES: top %d, bottom %d, sonar %d\n", sensing->getTopDistance(), sensing->getBottomDistance(), sensing->getSonarDistance(0));
msleep(90);
}
control->stop();
msleep(100);
for (int i = 0; i < STRATEGIES_COUNT; i++) {
delete strategies[i];
}
servo->setEventHandler(NULL);
delete servo;
delete control;
delete sensing;
power_button_reset();
return 0;
}