game.h 2.04 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
		virtual ~Game();

		

		void Wait(double wait); 

24
		Piece::Colour Setup(const char * redName, const char * blueName);
25
26
27
28
29
30
31
32
		MovementResult Play();
		void PrintEndMessage(const MovementResult & result);
		

		static void HandleBrokenPipe(int signal);
		
		
		const Piece::Colour Turn() const {return turn;}
33
		void ForceTurn(const Piece::Colour & newTurn) {turn = newTurn;}
34
35
36
		int TurnCount() const {return turnCount;}

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

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

		static bool gameCreated;

		FILE * input;

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

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;


};


86
87

#endif //MAIN_H