本文整理汇总了C++中AI::makeDecision方法的典型用法代码示例。如果您正苦于以下问题:C++ AI::makeDecision方法的具体用法?C++ AI::makeDecision怎么用?C++ AI::makeDecision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AI
的用法示例。
在下文中一共展示了AI::makeDecision方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]) {
if(argc != 3 && argc != 2){
std::cerr << "<usage>: client ip [port]" << std::endl;
return 1;
}
std::string message;
std::string port = argc == 3 ? argv[2] : "12345";
IO client(argv[1], port);
client.receive(message);
srand(static_cast<unsigned int>(time(0)+message[0]));
AI* ai = new AI(message[0]-'0');
client.send(ai->name() + '\n');
while (true) {
client.receive(message);
if (message == "game end") {
break;
} else if (message == "action") {
const Operation& op = ai->makeDecision();
auto decision = boost::format("%d %d %d\n") % op.source.x % op.source.y % DIR_CHAR[op.direction];
client.send(decision.str());
} else {
const int id = message[0]-'0';
const Point src(message[2]-'0', message[4]-'0');
const Point tar(message[6]-'0', message[8]-'0');
ai->update(id, src, tar);
}
}
}
示例2: main
//.........这里部分代码省略.........
if (event.key.code == sf::Keyboard::P)
pause = true;
}
#pragma endregion
// currently disabled
#pragma region framerate
//sf::Time frameRateTime = frameRateClock.getElapsedTime();
//float framerate = 1.0f / frameRateTime.asSeconds();
//printf("frameRate: %f \n", framerate );
//frameRateClock.restart().asSeconds();
#pragma endregion
window.clear();
if (view->isGamePlayChosen())
{
if (!(gameLogic->getGameOver()))
{
view->drawBackground();
#pragma region trigger automaticDrop
sf::Time elapsed = clock.getElapsedTime();
if (!pause)
{
if (elapsed.asSeconds() >= 0.1f)
{
if (gameLogic->getGeneticAlgorithmComputing())
{
clock.restart();
// returns true, if tetromino has landed. this also triggers spawning new tetrominos within gamelogic.cpp
if (gameLogic->dropAI())
{
// once the tetromino has landed, starting computation for next tetromino
ai->makeDecision(false);
}
}
else if (gameLogic->getFinishedAIPlays())
{
clock.restart();
// returns true, if tetromino has landed. this also triggers spawning new tetrominos within gamelogic.cpp
if (gameLogic->automaticDrop())
{
// once the tetromino has landed, starting computation for next tetromino
ai->makeDecision(false);
}
}
}
if (elapsed.asSeconds() >= 1.f - 0.05f * gameLogic->getLevel())
{
if (gameLogic->getSinglePlayer())
{
clock.restart();
gameLogic->automaticDrop();
}
}
}
else if (pause)
{
//drawPauseScreen();
}
#pragma endregion
view->drawCurrentTetromino();
view->drawNextTetro();
view->drawLandedArray();
view->drawInterface();
}
else
view->drawGameOver();
}
else
view->drawGamePlaySelection();
window.display();
}
/*delete ai;
delete gameLogic;
delete view;*/
return 0;
}