X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=manager%2Fmain.cpp;h=b0e2b4c55fa1aa0787d37ef0356cad9a7f9d4079;hb=HEAD;hp=6adc34de53d5c7970de288a22ecc5e9cb32c5456;hpb=4a3c0478160e7e9b637a12e7cf22f8da61b66ad2;p=progcomp2012.git diff --git a/manager/main.cpp b/manager/main.cpp deleted file mode 100644 index 6adc34d..0000000 --- a/manager/main.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include - - - - - - -#include "game.h" - -using namespace std; - -int main(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; - for (int ii=1; ii < argc; ++ii) - { - if (argv[ii][0] == '-') - { - switch (argv[ii][1]) - { - case 't': - if (argc - ii <= 1) - { - fprintf(stderr, "Expected timeout value after -t switch!\n"); - exit(EXIT_FAILURE); - } - timeout = atof(argv[ii+1]); - ++ii; - break; - case 'g': - graphics = true; - break; - case 'i': - allowIllegal = true; - break; - - case 'o': - if (argc - ii <= 1) - { - fprintf(stderr, "Expected filename or \"stdout\" after -o switch!\n"); - exit(EXIT_FAILURE); - } - if (log != NULL) - { - fprintf(stderr, "Expected at most ONE -o switch!\n"); - exit(EXIT_FAILURE); - } - if (strcmp(argv[ii+1], "stdout") == 0) - log = stdout; - else - log = fopen(argv[ii+1], "w"); - setbuf(log, NULL); - - ++ii; - break; - - case 'r': - if (reveal == Piece::BOTH) - reveal = Piece::BLUE; - else - reveal = Piece::NONE; - break; - case 'b': - if (reveal == Piece::BOTH) - reveal = Piece::RED; - else - reveal = Piece::NONE; - break; - case 'h': - system("clear"); - system("less manual.txt"); - exit(EXIT_SUCCESS); - break; - case '-': - if (strcmp(argv[ii]+2, "help") == 0) - { - system("clear"); - system("less manual.txt"); - exit(EXIT_SUCCESS); - } - else - { - fprintf(stderr, "Unrecognised switch \"%s\"...\n", argv[ii]); - exit(EXIT_FAILURE); - } - } - - } - else - { - if (red == NULL) - red = argv[ii]; - else if (blue == NULL) - blue = argv[ii]; - else - { - fprintf(stderr, "Unexpected argument \"%s\"...\n", argv[ii]); - exit(EXIT_FAILURE); - } - } - } - if (argc == 1) - { - fprintf(stderr, "Usage: stratego [options] red blue\n"); - fprintf(stderr, " stratego --help\n"); - exit(EXIT_SUCCESS); - - } - - Game game(red, blue, graphics, timeout, allowIllegal, log, reveal); - - - if (!game.Setup(red, blue)) - { - fprintf(stdout, "NONE %d\n",game.TurnCount()); - exit(EXIT_SUCCESS); - } - - MovementResult result = game.Play(); - game.PrintEndMessage(result); - - Piece::Colour winner = game.Turn(); - if (Board::LegalResult(result)) - { - if (winner == Piece::BOTH) - winner = Piece::NONE; - else - { - if (winner == Piece::RED) - winner = Piece::BLUE; - else - winner = Piece::RED; - } - } - - - switch (winner) - { - case Piece::RED: - fprintf(stdout, "%s RED %d\n", red,game.TurnCount()); - break; - case Piece::BLUE: - fprintf(stdout, "%s BLUE %d\n", blue,game.TurnCount()); - break; - case Piece::BOTH: - fprintf(stdout, "DRAW %d\n",game.TurnCount()); - break; - case Piece::NONE: - fprintf(stdout, "NONE %d\n",game.TurnCount()); - break; - - } - - - - - - - exit(EXIT_SUCCESS); - - return 0; -} - -