#include #include #include #include #include #include #include #include #include #include #include "game.h" static const char* sk_usage = #include "usage.h" ; // Verbose mode static const bool env_verbose = getenv("VERBOSE"); // time for waiting between file stats static const std::chrono::milliseconds sk_waitTime = std::chrono::milliseconds(100); // Check if a file exists inline bool FileExists( const std::string& name ) { struct stat buffer; return (stat (name.c_str(), &buffer) == 0); } // Wait for a file to exist inline void WaitForFile( const std::string& name, const std::chrono::milliseconds& time ) { while( !FileExists(name) ) std::this_thread::sleep_for(time); } bool OutputGameStateFile(CTTRTSGame &game, std::string &gameDir) { char turnFileName[128]; snprintf(turnFileName,128,"%s/Turn_%i.txt",gameDir.c_str(),game.GetTurn()); std::ofstream turnFile(turnFileName, std::ios_base::trunc); // truncate to overwrite if a file exists if ( turnFile.bad() ) { return false; } // Output the turn description std::string turnDescriptor = GetStringFromGame(game); turnFile<(file)),std::istreambuf_iterator()); if( gameDescriptor.size() == 0 ) { std::cerr<<"Error: failed to read in any information from "<>input; if( !input.size() || std::tolower(input[0]) != 'y' ) { std::cerr<<"Aborting..."<(turnFile)),std::istreambuf_iterator()); // Issue the orders to the game if( game.IssueOrders(player, orders) ) std::cerr<<"Warning: Orders for player "<<(int) player <<" failed to correctly parse"<