00001
00008 #pragma once
00009
00010 #include "utils.h"
00011 #include "timer.h"
00012 #include "board.h"
00013 #include "uct.h"
00014
00015 using std::vector;
00016
00017
00018
00019 #define CLOCK_CLICK_RESERVE 0.1
00020
00022 #define TC_MOVE_DEFAULT (cfg.tcMoveDefault())
00023
00024
00025
00026 #define TIME_CONTROLS_NUM 13
00027
00028 enum timeControl_e {TC_MOVE, TC_RESERVE, TC_PERCENT, TC_MAX, TC_TOTAL, TC_TURNS,
00029 TC_TURN_TIME, TC_W_RESERVE, TC_B_RESERVE, TC_W_USED, TC_B_USED,
00030 TC_MOVE_USED, TC_LAST_MOVE_USED};
00031
00032
00038 class TimeManager
00039 {
00040 public:
00041 TimeManager();
00042
00046 void startClock();
00047
00051 void stopClock();
00052
00059 bool timeUp();
00060
00064 double secondsElapsed();
00065
00072 void setTimeControl(timeControl_e tc, float value);
00073
00077 float getTimeControl(timeControl_e tc);
00078
00082 void setNoTimeLimit();
00083
00087 void resetSettings();
00088
00089 private:
00090 Timer timer;
00091 float timeControls_[TIME_CONTROLS_NUM];
00092 bool noTimeLimit_;
00093
00094 };
00095
00096
00103 class Engine
00104 {
00105 public:
00106 Engine();
00107 ~Engine();
00108
00112 string initialSetup(bool isGold) const;
00113
00117 void doSearch(const Board*);
00118
00124 void requestSearchStop();
00125
00129 TimeManager* timeManager();
00130
00134 void setPonder(bool value);
00135
00139 bool getPonder() const;
00140
00147 string getBestMove() const;
00148
00152 string getStats() const;
00153
00157 string getAdditionalInfo() const;
00158
00162 float getWinRatio() const;
00163
00170 bool checkSearchStop() const;
00171
00172 private:
00173
00177 void mockupSearchResults(const Board* board, Uct* uct[], Uct* masterUct, int resultsNum);
00178
00179 static void * searchTreeWrapper(void * searchTreeInfo);
00180
00181 TimeManager* timeManager_;
00182
00183 string bestMove_;
00184 string stats_;
00185 string additionalInfo_;
00186 float winRatio_;
00187
00189 bool ponder_;
00190
00192 bool stopRequest_;
00193 };
00194
00198 class SearchStartKit {
00199 public:
00200 SearchStartKit(const Board*, Engine*, Uct*);
00201
00202 private:
00204 const Board* board_;
00206 Engine* engineInstance_;
00208 Uct* uct_;
00209 friend class Engine;
00210 };
00211