13 void CreateGame(int argc, char ** argv);
15 void PrintResults(const MovementResult & result);
17 int main(int argc, char ** argv)
24 fprintf(stderr, "Usage: stratego [options] red blue\n");
25 fprintf(stderr, " stratego --help\n");
29 CreateGame(argc, argv);
30 if (Game::theGame == NULL)
32 fprintf(stderr, "ERROR: Couldn't create a game!\n");
36 MovementResult result = Game::theGame->Play();
37 Game::theGame->PrintEndMessage(result);
44 void CreateGame(int argc, char ** argv)
46 char * red = NULL; char * blue = NULL; double timeout = 0.00001; bool graphics = false; bool allowIllegal = false; FILE * log = NULL;
47 Piece::Colour reveal = Piece::BOTH; char * inputFile = NULL; int maxTurns = 5000; bool printBoard = false;
48 for (int ii=1; ii < argc; ++ii)
50 if (argv[ii][0] == '-')
57 fprintf(stderr, "Expected timeout value after -t switch!\n");
60 timeout = atof(argv[ii+1]);
67 printBoard = !printBoard;
70 allowIllegal = !allowIllegal;
76 fprintf(stderr, "Expected filename or \"stdout\" after -o switch!\n");
81 fprintf(stderr, "Expected at most ONE -o switch!\n");
84 if (strcmp(argv[ii+1], "stdout") == 0)
87 log = fopen(argv[ii+1], "w");
94 if (reveal == Piece::BOTH)
100 if (reveal == Piece::BOTH)
103 reveal = Piece::NONE;
108 fprintf(stderr, "Expected max_turns value after -m switch!\n");
111 if (strcmp(argv[ii+1], "inf"))
114 maxTurns = atoi(argv[ii+1]);
120 fprintf(stderr, "Expected filename after -f switch!\n");
125 fprintf(stderr, "Expected at most ONE -f switch!\n");
128 red = (char*)("file");
129 blue = (char*)("file");
130 inputFile = argv[ii+1];
135 system("less manual.txt");
139 if (strcmp(argv[ii]+2, "help") == 0)
142 system("less manual.txt");
147 fprintf(stderr, "Unrecognised switch \"%s\"...\n", argv[ii]);
157 else if (blue == NULL)
161 fprintf(stderr, "Unexpected argument \"%s\"...\n", argv[ii]);
167 if (inputFile == NULL)
169 Game::theGame = new Game(red,blue, graphics, timeout, allowIllegal,log, reveal,maxTurns, printBoard);
173 Game::theGame = new Game(inputFile, graphics, timeout, allowIllegal,log, reveal,maxTurns, printBoard);
175 if (!Game::theGame->Setup(red, blue))
177 fprintf(stdout, "NONE %d\n",Game::theGame->TurnCount());
185 void PrintResults(const MovementResult & result)
187 Piece::Colour winner = Game::theGame->Turn();
188 if (Board::LegalResult(result))
190 if (winner == Piece::BOTH)
191 winner = Piece::NONE;
194 if (winner == Piece::RED)
195 winner = Piece::BLUE;
205 fprintf(stdout, "%s RED %d\n", Game::theGame->red->name.c_str(),Game::theGame->TurnCount());
206 Game::theGame->logMessage("%s RED %d\n", Game::theGame->red->name.c_str(),Game::theGame->TurnCount());
209 fprintf(stdout, "%s BLUE %d\n", Game::theGame->blue->name.c_str(),Game::theGame->TurnCount());
210 Game::theGame->logMessage("%s BLUE %d\n", Game::theGame->blue->name.c_str(),Game::theGame->TurnCount());
213 fprintf(stdout, "DRAW %d\n",Game::theGame->TurnCount());
214 Game::theGame->logMessage("DRAW %d\n",Game::theGame->TurnCount());
217 fprintf(stdout, "NONE %d\n",Game::theGame->TurnCount());
218 Game::theGame->logMessage("NONE %d\n",Game::theGame->TurnCount());
226 delete Game::theGame;
227 Game::theGame = NULL;