当前位置: 首页>>代码示例>>C++>>正文


C++ AI::makeDecision方法代码示例

本文整理汇总了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);
        }
    }
}
开发者ID:abcdabcd987,项目名称:animal-ai,代码行数:32,代码来源:main.cpp

示例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;
}
开发者ID:zyko,项目名称:Tetris,代码行数:101,代码来源:main.cpp


注:本文中的AI::makeDecision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。