Merge branch 'master' of github.com:Meelo/NALCG
[NALCG.git] / src / middleman.h
blobbe925b5fefa4f7d2506c7776313b1c65f6957556
1 #ifndef _NALCG_MIDDLEMAN_H_
2 #define _NALCG_MIDDLEMAN_H_
4 // class includes
5 #include "ais/ai.h"
6 #include "ais/aiinfo.h"
7 #include "enduser.h"
8 #include "logic/colour.h"
9 #include "logic/board.h"
10 #include "logic/chesspieces-meta.h"
11 #include "client/remoteplayer.h"
13 // system includes
14 #include <cassert>
15 #include <vector>
17 class Middleman
19 public:
20 // Constants
21 static const unsigned int HALF_TURN = 1;
22 static const unsigned int FULL_TURN = 2;
24 Middleman(const std::vector<AI*>& aiList, const std::vector<AIInfo>& aiInfos);
25 virtual ~Middleman();
27 // Methods
28 void startGame();
30 std::vector<std::size_t> getValidMovesAt(std::size_t x, std::size_t y) const;
32 unsigned int move( std::size_t fromX, std::size_t fromY,
33 std::size_t toX, std::size_t toY,
34 unsigned int promoteTo = 0,
35 bool fromRemote = false);
37 void undo(unsigned int steps = FULL_TURN);
39 std::size_t getAICount() const { return aiList.size(); }
41 const AIInfo& getAIInfoAt(std::size_t index) const { return aiInfos.at(index); }
43 const std::vector<std::string>& getGameLog() const { return gameLog; }
45 const Board* getGameStateAt(std::size_t index) const { return gameStates.at(index); }
47 // Should be called *after* playRound(), since that updates currentPlayer.
48 unsigned int getGameConditionMask() const;
50 void addView(EndUser* _view) { view = _view; }
52 // 0 = Human, 1..n = AI player index + 1.
53 void setControl(unsigned int whiteController, unsigned int blackController);
55 // Methods (possibly) over IP
56 void sendChallenge(const std::string& remotePlayer);
58 void promptChallenge(const std::string& challenger);
60 void respondToChallenge(bool accept);
62 void updateUsers(const std::vector<std::string>& users);
64 private:
65 // Members
66 Board* board;
67 RemotePlayer client;
68 Colour currentTurn;
69 unsigned int rounds;
70 EndUser* view;
71 std::vector<AI*> aiList;
72 std::vector<AIInfo> aiInfos;
73 std::vector<Board*> gameStates;
74 std::vector<std::string> gameLog;
76 // Methods
77 void playRound();
79 void moveUpdate(std::size_t fromX, std::size_t fromY,
80 std::size_t toX, std::size_t toY, bool continuous = false);
82 void promoteUpdate( std::size_t fromX, std::size_t fromY,
83 std::size_t toX, std::size_t toY,
84 unsigned int promoteTo);
86 void remoteUpdate( std::size_t fromX, std::size_t fromY,
87 std::size_t toX, std::size_t toY,
88 unsigned int promoteTo);
90 void boardUpdate();
92 void updateBoardForAI();
94 const std::string newLogEntry( std::size_t fromX, std::size_t fromY,
95 std::size_t toX, std::size_t toY) const;
97 template <typename T>
98 void deleteAndClear(std::vector<T>& vector);
101 #endif // _NALCG_MIDDLEMAN_H_