[PATCH] Remove arguments, patch vixen, add hunter AI
[progcomp2012.git] / judge / manager / main.cpp
index 08c381c..b0e2b4c 100644 (file)
@@ -15,6 +15,8 @@ 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)
 {
        
@@ -50,12 +52,21 @@ 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;
 }
@@ -64,7 +75,9 @@ 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;
-       bool server = false; bool client = false;
+       char * imageOutput = (char*)"";
+
+
        for (int ii=1; ii < argc; ++ii)
        {
                if (argv[ii][0] == '-')
@@ -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");
@@ -185,26 +226,6 @@ Piece::Colour SetupGame(int argc, char ** argv)
                                                system("less manual.txt");
                                                exit(EXIT_SUCCESS);
                                        }
-                                       else if (strcmp(argv[ii]+2, "server") == 0)
-                                       {
-                                               if (client == true)
-                                               {
-                                                       fprintf(stderr, "ARGUMENT_ERROR - Can't be both a server and a client!\n");
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               server = true;
-                                               
-                                       }
-                                       else if (strcmp(argv[ii]+2, "client") == 0)
-                                       {
-                                               if (server == true)
-                                               {
-                                                       fprintf(stderr, "ARGUMENT_ERROR - Can't be both a server and a client!\n");
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               client = true;  
-                                               
-                                       }
                                        else
                                        {
                                                fprintf(stderr, "ARGUMENT_ERROR - Unrecognised switch \"%s\"...\n", argv[ii]);
@@ -232,38 +253,17 @@ Piece::Colour SetupGame(int argc, char ** argv)
 
        if (inputFile == NULL)
        {
-               if (server)  
+               if (red == NULL || blue == NULL) //Not enough players
                {
-                       if (red != NULL && blue != NULL)
-                       {
-                               fprintf(stderr, "ARGUMENT_ERROR - When using the --server switch, only supply ONE (1) player.\n");
-                               exit(EXIT_FAILURE);
-                       }
-               }
-               else if (red == NULL || blue == NULL) //Not enough players
-               {
-                       if (client)
-                               fprintf(stderr, "ARGUMENT_ERROR - When using the --client switch, supply an IP for the Red player.\n");
-                       else                    
-                               fprintf(stderr, "ARGUMENT_ERROR - Did not recieve enough players (did you mean to use the -f switch?)\n");      
+                       fprintf(stderr, "ARGUMENT_ERROR - Did not recieve enough players (did you mean to use the -f switch?)\n");      
                        exit(EXIT_FAILURE);     
                }
-               
-               if (client)
-               {
-                       blue = red; red = NULL;
-               }
 
-               Game::theGame = new Game(red,blue, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime, server, client);
+               Game::theGame = new Game(red,blue, graphics, stallTime, allowIllegal,log, reveal,maxTurns, printBoard, timeoutTime, imageOutput);
        }
        else
        {
-               if (server || client)
-               {
-                       fprintf(stderr, "ARGUMENT_ERROR - The -f switch is incompatable with the --server or --client switches!\n");
-                       exit(EXIT_FAILURE);
-               }
-               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)

UCC git Repository :: git.ucc.asn.au