Added faq and Copyright notice
[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 CheckVictoryAttrition();
27                 MovementResult Play();
28                 void PrintEndMessage(const MovementResult & result);
29                 
30
31                 static void HandleBrokenPipe(int signal);
32                 void ReadUserCommand();
33                 
34                 const Piece::Colour Turn() const {return turn;}
35                 void ForceTurn(const Piece::Colour & newTurn) {turn = newTurn;}
36                 int TurnCount() const {return turnCount;}
37
38                 static Game * theGame;
39                 static int Tokenise(std::vector<std::string> & buffer, std::string & str, char split = ' '); //Helper - Split a string into tokens
40         public:
41                 int logMessage(const char * format, ...);
42                 FILE * GetLogFile() const {return log;}
43                 Controller * red;
44                 Controller * blue;
45         private:
46                 Piece::Colour turn;
47                 
48         public:
49                 Board theBoard;
50         private:
51                 const bool graphicsEnabled;
52                 double stallTime;
53         public:
54                 const bool allowIllegalMoves;
55
56         private:
57                 FILE * log;
58                 
59         public:
60                 const Piece::Colour reveal;
61                 int turnCount;
62
63                 static bool gameCreated;
64
65                 FILE * input;
66
67                 int maxTurns;
68                 const bool printBoard;
69
70         private:
71                 double timeoutTime;
72                 
73 };
74
75 class FileController : public Controller
76 {
77         public:
78                 FileController(const Piece::Colour & newColour, FILE * newFile) : Controller(newColour, "file"), file(newFile) {}
79                 virtual ~FileController() {}
80
81                 virtual void Message(const char * string) {} //Don't send messages
82                 virtual MovementResult QuerySetup(const char * opponentName, std::string setup[]);
83                 virtual MovementResult QueryMove(std::string & buffer);
84                 virtual bool Valid() const {return file != NULL;}
85
86         private:
87                 FILE * file;
88
89
90 };
91
92
93
94 #endif //MAIN_H

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