Final AI tweaks.
[NALCG.git] / src / middleman.h
blobefb1070136344c192039577e84a932326f4bd826
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 void setAICutoffDepth(int white, int black);
57 // Methods (possibly) over IP
58 void sendChallenge(const std::string& remotePlayer);
60 void promptChallenge(const std::string& challenger);
62 void respondToChallenge(bool accept);
64 void updateUsers(const std::vector<std::string>& users);
66 bool connect();
68 private:
69 // Members
70 Board* board;
71 RemotePlayer client;
72 Colour currentTurn;
73 unsigned int rounds;
74 EndUser* view;
75 std::vector<AI*> aiList;
76 std::vector<AIInfo> aiInfos;
77 std::vector<Board*> gameStates;
78 std::vector<std::string> gameLog;
80 // Methods
81 void playRound();
83 void moveUpdate(std::size_t fromX, std::size_t fromY,
84 std::size_t toX, std::size_t toY, bool continuous = false);
86 void promoteUpdate( std::size_t fromX, std::size_t fromY,
87 std::size_t toX, std::size_t toY,
88 unsigned int promoteTo);
90 void remoteUpdate( std::size_t fromX, std::size_t fromY,
91 std::size_t toX, std::size_t toY,
92 unsigned int promoteTo);
94 void boardUpdate();
96 void updateBoardForAI();
98 const std::string newLogEntry( std::size_t fromX, std::size_t fromY,
99 std::size_t toX, std::size_t toY) const;
101 template <typename T>
102 void deleteAndClear(std::vector<T>& vector);
105 #endif // _NALCG_MIDDLEMAN_H_