Fixed bug with log files
[progcomp2012.git] / judge / manager / game.h
1 #ifndef MAIN_H
2 #define MAIN_H
3
4 #include "stratego.h"
5 #include "ai_controller.h"
6 #include "human_controller.h"
7 #include "network_controller.h"
8 #include <cstring>
9
10
11 /**
12  * Class to manage the game
13  * Bit messy since I keep adding on parameters :P
14  */
15 class Game
16 {
17         public:
18                 Game(const char * redPath, const char * bluePath, const bool enableGraphics, double newStallTime = 1.0, const bool allowIllegal=false, FILE * newLog = NULL, const Piece::Colour & newRevealed = Piece::BOTH, int maxTurns = 5000, const bool printBoard = false, double newTimeoutTime = 2.0);
19                 Game(const char * fromFile, const bool enableGraphics, double newStallTime = 1.0, const bool allowIllegal=false, FILE * newLog = NULL, const Piece::Colour & newRevealed = Piece::BOTH, int maxTurns = 5000, const bool printBoard = false, double newTimeoutTime = 2.0);
20                 virtual ~Game();
21
22                 
23
24                 void Wait(double wait); 
25
26                 Piece::Colour Setup(const char * redName, const char * blueName);
27                 MovementResult CheckVictoryAttrition();
28                 MovementResult Play();
29                 void PrintEndMessage(const MovementResult & result);
30                 
31
32                 static void HandleBrokenPipe(int signal);
33                 void ReadUserCommand();
34                 
35                 const Piece::Colour Turn() const {return turn;}
36                 void ForceTurn(const Piece::Colour & newTurn) {turn = newTurn;}
37                 int TurnCount() const {return turnCount;}
38
39                 static Game * theGame;
40                 static int Tokenise(std::vector<std::string> & buffer, std::string & str, char split = ' '); //Helper - Split a string into tokens
41
42         private:
43                 void MakeControllers(const char * redPath, const char * bluePath); //Create a controller based off a path
44         public:
45                 int logMessage(const char * format, ...);
46                 FILE * GetLogFile() const {return log;}
47                 Controller * red;
48                 Controller * blue;
49         private:
50                 Piece::Colour turn;
51                 
52         public:
53                 Board theBoard;
54         private:
55                 const bool graphicsEnabled;
56                 double stallTime;
57         public:
58                 const bool allowIllegalMoves;
59
60         private:
61                 FILE * log;
62                 
63         public:
64                 const Piece::Colour reveal;
65                 int turnCount;
66
67                 static bool gameCreated;
68
69                 FILE * input;
70
71                 int maxTurns;
72                 const bool printBoard;
73
74         private:
75                 double timeoutTime;
76                 
77 };
78
79 class FileController : public Controller
80 {
81         public:
82                 FileController(const Piece::Colour & newColour, FILE * newFile) : Controller(newColour, "file"), file(newFile) {}
83                 virtual ~FileController() {}
84
85                 virtual void Message(const char * string) {} //Don't send messages
86                 virtual MovementResult QuerySetup(const char * opponentName, std::string setup[]);
87                 virtual MovementResult QueryMove(std::string & buffer);
88                 virtual bool Valid() const {return file != NULL;}
89
90         private:
91                 FILE * file;
92
93
94 };
95
96
97
98 #endif //MAIN_H

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