Modified manager output/protocol, added "basic" AI, made Asmodeus better
[progcomp2012.git] / 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                 
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                 Piece::Colour reveal;
57                 int turnCount;
58
59                 static bool gameCreated;
60
61                 FILE * input;
62
63                 int maxTurns;
64                 const bool printBoard;
65                 
66 };
67
68 class FileController : public Controller
69 {
70         public:
71                 FileController(const Piece::Colour & newColour, FILE * newFile) : Controller(newColour, "file"), file(newFile) {}
72                 virtual ~FileController() {}
73
74                 virtual void Message(const char * string) {} //Don't send messages
75                 virtual MovementResult QuerySetup(const char * opponentName, std::string setup[]);
76                 virtual MovementResult QueryMove(std::string & buffer);
77                 virtual bool Valid() const {return file != NULL;}
78
79         private:
80                 FILE * file;
81
82
83 };
84
85
86
87 #endif //MAIN_H

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