Add version 1.2 of Celsius
[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, const char * newImageOutput = "");
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, const char * newImageOutput = "");
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                 static void PrintResults(const MovementResult & result, std::string & buffer);
47                 FILE * GetLogFile() const {return log;}
48                 Controller * red;
49                 Controller * blue;
50         private:
51                 Piece::Colour turn;
52                 
53         public:
54                 Board theBoard;
55         private:
56                 const bool graphicsEnabled;
57                 double stallTime;
58         public:
59                 const bool allowIllegalMoves;
60
61         private:
62                 FILE * log;
63                 
64         public:
65                 const Piece::Colour reveal;
66                 int turnCount;
67
68                 static bool gameCreated;
69
70                 FILE * input;
71
72                 int maxTurns;
73                 const bool printBoard;
74
75         private:
76                 double timeoutTime;
77                 std::string imageOutput;
78                 
79 };
80
81 class FileController : public Controller
82 {
83         public:
84                 FileController(const Piece::Colour & newColour, FILE * newFile) : Controller(newColour, "file"), file(newFile) {}
85                 virtual ~FileController() {}
86
87                 virtual bool Message(const char * string) {return true;} //Don't send messages
88                 virtual MovementResult QuerySetup(const char * opponentName, std::string setup[]);
89                 virtual MovementResult QueryMove(std::string & buffer);
90                 virtual bool Valid() const {return file != NULL;}
91
92         private:
93                 FILE * file;
94
95
96 };
97
98 std::string itostr(int i);
99
100
101 #endif //MAIN_H

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