game.h 1.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef MAIN_H
#define MAIN_H

#include "stratego.h"
#include "ai_controller.h"
#include "human_controller.h"



/**
 * Class to manage the game
 */
class Game
{
	public:
16
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);
		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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
		virtual ~Game();

		

		void Wait(double wait); 

		bool Setup(const char * redName, const char * blueName);
		MovementResult Play();
		void PrintEndMessage(const MovementResult & result);
		

		static void HandleBrokenPipe(int signal);
		
		
		const Piece::Colour Turn() const {return turn;}
		int TurnCount() const {return turnCount;}

		static Game * theGame;
36
	public:
37
		int logMessage(const char * format, ...);
38
		FILE * GetLogFile() const {return log;}
39
40
		Controller * red;
		Controller * blue;
41
	private:
42
43
44
45
46
47
48
49
50
51
52
53
		Piece::Colour turn;
		
	public:
		Board theBoard;
	private:
		const bool graphicsEnabled;
		double stallTime;
	public:
		const bool allowIllegalMoves;

	private:
		FILE * log;
54
		
55
56
		Piece::Colour reveal;
		int turnCount;
57
58
59
60
61
62
63

		static bool gameCreated;

		FILE * input;

		int maxTurns;
		const bool printBoard;
64
65
66
		
};

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class FileController : public Controller
{
	public:
		FileController(const Piece::Colour & newColour, FILE * newFile) : Controller(newColour, "file"), file(newFile) {}
		virtual ~FileController() {}

		virtual void Message(const char * string) {} //Don't send messages
		virtual MovementResult QuerySetup(const char * opponentName, std::string setup[]);
		virtual MovementResult QueryMove(std::string & buffer);
		virtual bool Valid() const {return file != NULL;}

	private:
		FILE * file;


};


85
86

#endif //MAIN_H