00001
00008 #pragma once
00009
00010 #include <list>
00011
00012 #include "utils.h"
00013 #include "config.h"
00014 #include "board.h"
00015 #include "engine.h"
00016 #include "uct.h"
00017
00018 using std::list;
00019 using std::flush;
00020
00021
00022 #define ID_NAME "akimot"
00023 #define ID_AUTHOR "Tomas Kozelek"
00024 #define ID_VERSION "0.1"
00025
00026
00027 enum aeiState_e {AS_ALL, AS_SAME, AS_OPEN, AS_MAIN, AS_GAME, AS_SEARCH, AS_PONDER};
00028 enum aeiAction_e {AA_OPEN, AA_READY, AA_QUIT, AA_SET_POSITION,
00029 AA_SET_POSITION_FILE, AA_SET_OPTION, AA_NEW_GAME, AA_SET_VARIABLE,
00030 AA_GO, AA_GO_NO_THREAD, AA_STOP, AA_MAKE_MOVE, AA_MAKE_MOVE_REC,
00031 AA_BOARD_DUMP, AA_TREE_DUMP, AA_GOAL_CHECK, AA_TRAP_CHECK, AA_EVAL};
00032 enum aeiLogLevel_e {AL_ERROR, AL_WARNING, AL_INFO, AL_DEBUG};
00033
00040 enum aeiCommandSet_e {AC_STD, AC_EXT};
00041
00042 class Engine;
00043 class Aei;
00044
00045
00052 class AeiRecord
00053 {
00054 public:
00055 AeiRecord(string command, aeiState_e state, aeiState_e nextState,
00056 aeiAction_e action);
00057 AeiRecord(string command, aeiState_e state, aeiState_e nextState,
00058 aeiAction_e action, aeiCommandSet_e commandSet_);
00059
00060 private:
00061 aeiState_e state_;
00062 string command_;
00063 aeiState_e nextState_;
00064 aeiAction_e action_;
00065 aeiCommandSet_e commandSet_;
00066 friend class Aei;
00067 };
00068
00069
00070 typedef list<AeiRecord> AeiRecordList;
00071 typedef pair<string, timeControl_e> timeControlPair;
00072 typedef list<timeControlPair> TimeControlList;
00073
00074
00081 class Aei
00082 {
00083 public:
00084 Aei();
00085 ~Aei();
00086
00090 Aei(aeiCommandSet_e commandSet);
00091
00095 void runLoop();
00096
00102 void initFromFile(string fn);
00103
00104 private:
00111 void init();
00112
00116 void handleInput(const string& input);
00117
00121 void handleOption(const string& commandRest);
00122
00128 void startSearch(const string& arg);
00129
00133 void goalCheck();
00134
00138 void trapCheck();
00139
00143 void evalActPos();
00144
00148 void searchInThread();
00149
00155 static void* SearchInThreadWrapper(void *instance);
00156
00157
00168 void stopSearch(bool fromThread=false);
00169
00173 void sendSearchInfo();
00174
00178 void aeiLog(const string& msg, const aeiLogLevel_e logLevel) const;
00179
00183 void sendInfo(const string& type, const string& value) const;
00184
00188 void quit() const;
00189
00195 void sendId() const;
00196
00200 void send(const string& s) const;
00201
00203 AeiRecordList records_;
00205 TimeControlList timeControls_;
00207 aeiState_e state_;
00209 string response_;
00210
00211 aeiCommandSet_e commandSet_;
00212
00213
00214 Board* board_;
00215 Engine* engine_;
00217 pthread_t engineThread_;
00218 };
00219