-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaei.h
More file actions
218 lines (178 loc) · 4.82 KB
/
Copy pathaei.h
File metadata and controls
218 lines (178 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/**
* @file aei.h
* Arimaa engine interface.
*
* Definition of AEI commands and their dispatching.
*/
#pragma once
#include <list>
#include "utils.h"
#include "config.h"
#include "board.h"
#include "engine.h"
#include "uct.h"
using std::list;
using std::flush;
#define ID_NAME "akimot"
#define ID_AUTHOR "Tomas Kozelek"
#define ID_VERSION "0.1"
enum aeiState_e {AS_ALL, AS_SAME, AS_OPEN, AS_MAIN, AS_GAME, AS_SEARCH, AS_PONDER};
enum aeiAction_e {AA_OPEN, AA_READY, AA_QUIT, AA_SET_POSITION,
AA_SET_POSITION_FILE, AA_SET_OPTION, AA_NEW_GAME, AA_SET_VARIABLE,
AA_GO, AA_GO_NO_THREAD, AA_STOP, AA_MAKE_MOVE, AA_MAKE_MOVE_REC,
AA_BOARD_DUMP, AA_TREE_DUMP, AA_GOAL_CHECK, AA_TRAP_CHECK, AA_EVAL};
enum aeiLogLevel_e {AL_ERROR, AL_WARNING, AL_INFO, AL_DEBUG};
/**
* Command Set definition
* AC_STD : standard AEI
* AC_EXT : extended AC_STD with debug/shortcut stuff.
* More info in states definition.
*/
enum aeiCommandSet_e {AC_STD, AC_EXT};
class Engine;
class Aei;
/**
* One record in aei finite automata.
*
* Defines state + command -> newstate + action.
* Action is then handled in Aei::handleInput.
*/
class AeiRecord
{
public:
AeiRecord(string command, aeiState_e state, aeiState_e nextState,
aeiAction_e action);
AeiRecord(string command, aeiState_e state, aeiState_e nextState,
aeiAction_e action, aeiCommandSet_e commandSet_);
private:
aeiState_e state_;
string command_;
aeiState_e nextState_;
aeiAction_e action_;
aeiCommandSet_e commandSet_;
friend class Aei;
};
typedef list<AeiRecord> AeiRecordList;
typedef pair<string, timeControl_e> timeControlPair;
typedef list<timeControlPair> TimeControlList;
/**
* Arimaa Engine Interface Controller.
*
* This class operates communication with external interface(gameroom, user)
* and controls the searching engine.
*/
class Aei
{
public:
Aei();
~Aei();
/**
* Constructor with specified command set.
*/
Aei(aeiCommandSet_e commandSet);
/**
* Waits for commands in loop.
*/
void runLoop();
/**
* Hardcoded beginning of session.
*
* For debugging purposes.
*/
void initFromFile(string fn);
private:
/**
* Initialization.
*
* Inits the parsing automata states and variables.
* Reused in both constructors.
*/
void init();
/**
* Handles single command;
*/
void handleInput(const string& input);
/**
* Parse option from setoption command.
*/
void handleOption(const string& commandRest);
/**
* Initiates thread creation and search start.
*
* @param arg Search arguments - e.g. ponder, infinite, etc.
*/
void startSearch(const string& arg);
/**
* Performs static goal check on the current position.
*/
void goalCheck();
/**
* Performs static trap check on the current position.
*/
void trapCheck();
/**
* Evaluates actual position.
*/
void evalActPos();
/**
* Threaded wrapper around engine.doSearch().
*/
void searchInThread();
/**
* Wrapper around Aei::searchinThread().
*
* Declared as static so it can be threaded.
*/
static void* SearchInThreadWrapper(void *instance);
/**
* Stop search.
*
* Gives request to stop the search.
* Waits for the search thread to join.
*
* @param fromThread If true, method is called from thread
* -> doesn't need to join the thread
* otherwise does nothing ( e.g. when makemove stopped go ponder)
*/
void stopSearch(bool fromThread=false);
/**
* Sends bestmove/winration/timeinfo.
*/
void sendSearchInfo();
/**
* Communicate log messages.
*/
void aeiLog(const string& msg, const aeiLogLevel_e logLevel) const;
/**
* Sending additional information.
*/
void sendInfo(const string& type, const string& value) const;
/**
* Quit the program.
*/
void quit() const;
/**
* Send id information.
*
* Uses information from ID_ macros - ID_AUTHOR, IT_NAME, ID_VERSION.
*/
void sendId() const;
/**
* Wrapper around sending.
*/
void send(const string& s) const;
/** Records of aei finite automata.*/
AeiRecordList records_;
/** List of pairs <option name, time control for time manager>*/
TimeControlList timeControls_;
/** State of the automata.*/
aeiState_e state_;
/** Response to be send through communication channel.*/
string response_;
aeiCommandSet_e commandSet_;
//bool sendMoveAfterSearch_;
Board* board_;
Engine* engine_;
/** Thread handler for running search.*/
pthread_t engineThread_;
};