Fixed bugs, minor changes
[progcomp2012.git] / progcomp / 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
8
9
10 /**
11  * Class to manage the game
12  */
13 class Game
14 {
15         public:
16                 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);
17                 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);
18                 virtual ~Game();
19
20                 
21
22                 void Wait(double wait); 
23
24                 Piece::Colour Setup(const char * redName, const char * blueName);
25                 MovementResult Play();
26                 void PrintEndMessage(const MovementResult & result);
27                 
28
29                 static void HandleBrokenPipe(int signal);
30                 void ReadUserCommand();
31                 
32                 const Piece::Colour Turn() const {return turn;}
33                 void ForceTurn(const Piece::Colour & newTurn) {turn = newTurn;}
34                 int TurnCount() const {return turnCount;}
35
36                 static Game * theGame;
37         public:
38                 int logMessage(const char * format, ...);
39                 FILE * GetLogFile() const {return log;}
40                 Controller * red;
41                 Controller * blue;
42         private:
43                 Piece::Colour turn;
44                 
45         public:
46                 Board theBoard;
47         private:
48                 const bool graphicsEnabled;
49                 double stallTime;
50         public:
51                 const bool allowIllegalMoves;
52
53         private:
54                 FILE * log;
55                 
56         public:
57                 const Piece::Colour reveal;
58                 int turnCount;
59
60                 static bool gameCreated;
61
62                 FILE * input;
63
64                 int maxTurns;
65                 const bool printBoard;
66                 
67 };
68
69 class FileController : public Controller
70 {
71         public:
72                 FileController(const Piece::Colour & newColour, FILE * newFile) : Controller(newColour, "file"), file(newFile) {}
73                 virtual ~FileController() {}
74
75                 virtual void Message(const char * string) {} //Don't send messages
76                 virtual MovementResult QuerySetup(const char * opponentName, std::string setup[]);
77                 virtual MovementResult QueryMove(std::string & buffer);
78                 virtual bool Valid() const {return file != NULL;}
79
80         private:
81                 FILE * file;
82
83
84 };
85
86
87
88 #endif //MAIN_H

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