X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=judge%2Fmanager%2Fmain.cpp;h=ee3583701b849c2f8359563b84515acf07cd03e6;hp=e65ef0d1b6a142781f821fc076a2d42b21b0d29d;hb=add28d0a7f265f5fcfdd67a4c1e590b19f76272e;hpb=341297b4dce9528d54fe9dceeff0d6dc33f70abe diff --git a/judge/manager/main.cpp b/judge/manager/main.cpp index e65ef0d..ee35837 100644 --- a/judge/manager/main.cpp +++ b/judge/manager/main.cpp @@ -13,7 +13,9 @@ 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) { @@ -44,18 +46,27 @@ int main(int argc, char ** argv) Game::theGame->PrintEndMessage(result); string buffer = ""; - PrintResults(result, buffer); + Game::PrintResults(result, buffer); //Message the AI's the quit message 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; } @@ -64,6 +75,8 @@ Piece::Colour SetupGame(int argc, char ** argv) { 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) { @@ -99,7 +112,7 @@ Piece::Colour SetupGame(int argc, char ** argv) case 'g': #ifdef BUILD_GRAPHICS - graphics = !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); @@ -173,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"); @@ -218,11 +259,11 @@ Piece::Colour SetupGame(int argc, char ** argv) exit(EXIT_FAILURE); } - Game::theGame = new Game(red,blue, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime); + Game::theGame = new Game(red,blue, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime, imageOutput); } else { - Game::theGame = new Game(inputFile, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime); + Game::theGame = new Game(inputFile, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime, imageOutput); } if (Game::theGame == NULL) @@ -237,61 +278,6 @@ Piece::Colour SetupGame(int argc, char ** argv) } -void PrintResults(const MovementResult & result, string & buffer) -{ - stringstream s(""); - switch (Game::theGame->Turn()) - { - case Piece::RED: - s << Game::theGame->red->name << " RED "; - break; - case Piece::BLUE: - s << Game::theGame->blue->name << " BLUE "; - break; - case Piece::BOTH: - s << "neither BOTH "; - break; - case Piece::NONE: - s << "neither NONE "; - break; - } - - if (!Board::LegalResult(result) && result != MovementResult::BAD_SETUP) - s << "ILLEGAL "; - else if (!Board::HaltResult(result)) - s << "INTERNAL_ERROR "; - else - { - switch (result.type) - { - 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: - s << "SURRENDER "; - break; - case MovementResult::DRAW: - s << "DRAW "; - break; - case MovementResult::DRAW_DEFAULT: - s << "DRAW_DEFAULT "; - break; - case MovementResult::BAD_SETUP: - s << "BAD_SETUP "; - break; - default: - s << "INTERNAL_ERROR "; - break; - } - } - - s << Game::theGame->TurnCount() << " " << Game::theGame->theBoard.TotalPieceValue(Piece::RED) << " " << Game::theGame->theBoard.TotalPieceValue(Piece::BLUE); - - buffer = s.str(); - - -} void DestroyGame() {