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

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