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

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