X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=judge%2Fmanager%2Fmain.cpp;h=b0e2b4c55fa1aa0787d37ef0356cad9a7f9d4079;hp=0fbd6aef6c35d51476a33407681a28a2e11a6530;hb=ac335e7c423d067effae82cc80db518f896271b9;hpb=1a03b2543b67f0551e62babec4cd119f1e0e4640 diff --git a/judge/manager/main.cpp b/judge/manager/main.cpp index 0fbd6ae..b0e2b4c 100644 --- a/judge/manager/main.cpp +++ b/judge/manager/main.cpp @@ -8,12 +8,15 @@ #include "game.h" + using namespace std; Piece::Colour SetupGame(int argc, char ** argv); void DestroyGame(); void PrintResults(const MovementResult & result, string & buffer); +char * video = NULL; + int main(int argc, char ** argv) { @@ -49,20 +52,32 @@ int main(int argc, char ** argv) Game::theGame->red->Message("QUIT " + buffer); Game::theGame->blue->Message("QUIT " + buffer); + if (video != NULL) + { + string command = "mv "; command += video; command += " tmp; cd tmp; ffmpeg -r 10 -b 1024k -i %d.bmp "; command += video; + command += ";mv "; command += video; command += " ../; cd ../; rm -rf tmp;"; + system(command.c_str()); + } + //Log the message if (Game::theGame->GetLogFile() != stdout) Game::theGame->logMessage("%s\n", buffer.c_str()); fprintf(stdout, "%s\n", buffer.c_str()); + + exit(EXIT_SUCCESS); return 0; } Piece::Colour SetupGame(int argc, char ** argv) { - char * red = NULL; char * blue = NULL; double timeout = 0.00001; bool graphics = false; bool allowIllegal = false; FILE * log = NULL; - Piece::Colour reveal = Piece::BOTH; char * inputFile = NULL; int maxTurns = 5000; bool printBoard = false; + char * red = NULL; char * blue = NULL; double stallTime = 0.0; bool graphics = false; bool allowIllegal = false; FILE * log = NULL; + Piece::Colour reveal = Piece::BOTH; char * inputFile = NULL; int maxTurns = 5000; bool printBoard = false; double timeoutTime = 2.0; + char * imageOutput = (char*)""; + + for (int ii=1; ii < argc; ++ii) { if (argv[ii][0] == '-') @@ -72,17 +87,37 @@ Piece::Colour SetupGame(int argc, char ** argv) case 't': if (argc - ii <= 1) { - fprintf(stderr, "ARGUMENT_ERROR - Expected timeout value after -t switch!\n"); + fprintf(stderr, "ARGUMENT_ERROR - Expected stall time value after -t switch!\n"); exit(EXIT_FAILURE); } if (strcmp(argv[ii+1], "inf") == 0) - timeout = -1; + stallTime = -1; else - timeout = atof(argv[ii+1]); + stallTime = atof(argv[ii+1]); ++ii; break; + + case 'T': + if (argc - ii <= 1) + { + fprintf(stderr, "ARGUMENT_ERROR - Expected timeout value after -T switch!\n"); + exit(EXIT_FAILURE); + } + if (strcmp(argv[ii+1], "inf") == 0) + timeoutTime = -1; + else + timeoutTime = atof(argv[ii+1]); + ++ii; + break; + case 'g': - graphics = !graphics; + #ifdef BUILD_GRAPHICS + graphics = true; + #else + fprintf(stderr, "ERROR: -g switch supplied, but the program was not built with graphics.\n Please do not use the -g switch."); + exit(EXIT_FAILURE); + #endif //BUILD_GRAPHICS + break; case 'p': printBoard = !printBoard; @@ -151,6 +186,34 @@ Piece::Colour SetupGame(int argc, char ** argv) inputFile = argv[ii+1]; ++ii; break; + case 'v': + #ifdef BUILD_GRAPHICS + video = argv[ii+1]; + #endif //BUILD_GRAPHICS + case 'I': + { + #ifdef BUILD_GRAPHICS + graphics = true; + if (argc - ii <= 1) + { + fprintf(stderr, "ARGUMENT_ERROR - Expected filename after -I switch!\n"); + exit(EXIT_FAILURE); + } + imageOutput = argv[ii+1]; + string m("mkdir -p "); m += imageOutput; + system(m.c_str()); + ++ii; + #else + fprintf(stderr, "ERROR: -%c switch supplied, but the program was not built with graphics."); + exit(EXIT_FAILURE); + #endif //BUILD_GRAPHICS + + break; + + } + + + case 'h': system("clear"); system("less manual.txt"); @@ -185,20 +248,22 @@ Piece::Colour SetupGame(int argc, char ** argv) } } - + if (graphics && stallTime == 0.0) + stallTime = 0.00001; //Hack so that SDL events (ie SDL_QUIT) will have time to be captured when graphics are enabled if (inputFile == NULL) { - if (red == NULL || blue == NULL) //Not enough arguments + if (red == NULL || blue == NULL) //Not enough players { fprintf(stderr, "ARGUMENT_ERROR - Did not recieve enough players (did you mean to use the -f switch?)\n"); exit(EXIT_FAILURE); } - Game::theGame = new Game(red,blue, graphics, timeout, allowIllegal,log, reveal,maxTurns, printBoard); + + Game::theGame = new Game(red,blue, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime, imageOutput); } else { - Game::theGame = new Game(inputFile, graphics, timeout, allowIllegal,log, reveal,maxTurns, printBoard); + Game::theGame = new Game(inputFile, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime, imageOutput); } if (Game::theGame == NULL) @@ -240,7 +305,8 @@ void PrintResults(const MovementResult & result, string & buffer) { switch (result.type) { - case MovementResult::VICTORY: + case MovementResult::VICTORY_FLAG: + case MovementResult::VICTORY_ATTRITION: //It does not matter how you win, it just matters that you won! s << "VICTORY "; break; case MovementResult::SURRENDER: