Game* Game::theGame = NULL;
bool Game::gameCreated = false;
-Game::Game(const char * redPath, const char * bluePath, const bool enableGraphics, double newStallTime, const bool allowIllegal, FILE * newLog, const Piece::Colour & newReveal, int newMaxTurns, bool newPrintBoard, double newTimeoutTime) : red(NULL), blue(NULL), turn(Piece::RED), theBoard(10,10), graphicsEnabled(enableGraphics), stallTime(newStallTime), allowIllegalMoves(allowIllegal), log(newLog), reveal(newReveal), turnCount(0), input(NULL), maxTurns(newMaxTurns), printBoard(newPrintBoard), timeoutTime(newTimeoutTime)
+Game::Game(const char * redPath, const char * bluePath, const bool enableGraphics, double newStallTime, const bool allowIllegal, FILE * newLog, const Piece::Colour & newReveal, int newMaxTurns, bool newPrintBoard, double newTimeoutTime, const char * newImageOutput) : red(NULL), blue(NULL), turn(Piece::RED), theBoard(10,10), graphicsEnabled(enableGraphics), stallTime(newStallTime), allowIllegalMoves(allowIllegal), log(newLog), reveal(newReveal), turnCount(0), input(NULL), maxTurns(newMaxTurns), printBoard(newPrintBoard), timeoutTime(newTimeoutTime), imageOutput(newImageOutput)
{
gameCreated = false;
if (gameCreated)
fprintf(stderr, "BLUE! (blue: \"%s\")\n", bluePath);
exit(EXIT_FAILURE);
}
- logMessage("Game initialised.\n");
+// logMessage("Game initialised.\n");
}
-Game::Game(const char * fromFile, const bool enableGraphics, double newStallTime, const bool allowIllegal, FILE * newLog, const Piece::Colour & newReveal, int newMaxTurns, bool newPrintBoard, double newTimeoutTime) : red(NULL), blue(NULL), turn(Piece::RED), theBoard(10,10), graphicsEnabled(enableGraphics), stallTime(newStallTime), allowIllegalMoves(allowIllegal), log(newLog), reveal(newReveal), turnCount(0), input(NULL), maxTurns(newMaxTurns), printBoard(newPrintBoard), timeoutTime(newTimeoutTime)
+Game::Game(const char * fromFile, const bool enableGraphics, double newStallTime, const bool allowIllegal, FILE * newLog, const Piece::Colour & newReveal, int newMaxTurns, bool newPrintBoard, double newTimeoutTime,const char * newImageOutput) : red(NULL), blue(NULL), turn(Piece::RED), theBoard(10,10), graphicsEnabled(enableGraphics), stallTime(newStallTime), allowIllegalMoves(allowIllegal), log(newLog), reveal(newReveal), turnCount(0), input(NULL), maxTurns(newMaxTurns), printBoard(newPrintBoard), timeoutTime(newTimeoutTime), imageOutput(newImageOutput)
{
gameCreated = false;
if (gameCreated)
- logMessage("Messaging red with \"START\"\n");
+// logMessage("Messaging red with \"START\"\n");
red->Message("START");
-
+ int moveCount = 0;
while (!Board::HaltResult(result) && (turnCount < maxTurns || maxTurns < 0))
{
#ifdef BUILD_GRAPHICS
if (graphicsEnabled)
+ {
theBoard.Draw(toReveal);
+ if (imageOutput != "")
+ {
+ string imageFile = "" + imageOutput + "/"+ itostr(moveCount) + ".bmp";
+ Graphics::ScreenShot(imageFile.c_str());
+ }
+
+ }
#endif //BUILD_GRAPHICS
turn = Piece::RED;
theBoard.PrintPretty(stdout, toReveal);
fprintf(stdout, "\n\n");
}
+
+ ++moveCount;
#ifdef BUILD_GRAPHICS
if (graphicsEnabled)
+ {
theBoard.Draw(toReveal);
+ if (imageOutput != "")
+ {
+ string imageFile = "" + imageOutput + "/" + itostr(moveCount) + ".bmp";
+ Graphics::ScreenShot(imageFile.c_str());
+ }
+ }
#endif //BUILD_GRAPHICS
else
ReadUserCommand();
-
+ ++moveCount;
++turnCount;
}
{
Network * redNetwork = NULL;
Network * blueNetwork = NULL;
+ //To allow for running two network controllers (I don't know why you would, but beside the point...) use two ports
+ static const int port1 = 4560;
+ static const int port2 = 4561;
if (redPath[0] == '@')
{
if (network == NULL)
{
logMessage("Creating server for red AI... ");
- redNetwork = new Server();
+ redNetwork = new Server(port1);
logMessage("Successful!\n");
}
{
network = (const char*)(network+1);
logMessage("Creating client for red AI... ");
- redNetwork = new Client(network);
+ redNetwork = new Client(network, port2);
logMessage("Connected to address %s\n", network);
}
if (network == NULL)
{
logMessage("Creating server for blue AI... ");
- blueNetwork = new Server();
+ blueNetwork = new Server(port2);
logMessage("Successful!\n");
}
{
network = (const char*)(network+1);
logMessage("Creating client for blue AI... ");
- blueNetwork = new Client(network);
+ blueNetwork = new Client(network, port1);
logMessage("Connected to address %s\n", network);
}
logMessage(" (Blue's responses will be received over the connection)\n");
red = new NetworkSender(Piece::RED, red, blueNetwork);
logMessage(" (Red's responses will be copied over the connection)\n");
}
+
+ red->FixName(); blue->FixName();
}
+string itostr(int i)
+{
+ stringstream s;
+ s << i;
+ return s.str();
+}
+