Belofte version 2.1.9
A promising chess program using the UCI or Winboard interface
usercmd.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: usercmd.h
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#if !defined(USERCMD_H)
9#define USERCMD_H
10
11/**
12 * basic format for single command
13 */
15public:
16 engineUserCommand(std::string const& s, std::string const& h)
17 : m_name(s)
18 , m_hint(h)
19 {}
21 {}
22
23 // no copy or move ctor nor assignment defined
28
29 virtual void execute(std::string const& args);
30
31 // declared public as there is not much logic and to avoid getter/setter
32 std::string m_name;
33 std::string m_hint;
34 bool m_isImplemented = true;
35 bool m_isHidden = false;
36};
37
38/**
39 * command and parameters
40 */
41class cmdParam {
42public:
44 : m_command("")
45 , m_args("")
46 {}
48 {}
49
50 cmdParam(cmdParam&&) = default;
51
52 // no copy or move ctor nor assignment defined
53 cmdParam(cmdParam const&) = delete;
54 cmdParam& operator=(cmdParam const&) = delete;
56
57 // declared public as there is not much logic and to avoid getter/setter
58 std::string m_command;
59 std::string m_args;
60};
61
62//-----------------------------------------------------------------------
63
64/**
65 * Sub-class to react uniformly on UCI interface specific stuff
66 */
68public:
69 UCIengineCommand(std::string const& s, std::string const& h)
70 : engineUserCommand(s, h)
71 {}
73 {}
74};
75
77public:
78 UCIengineOption(std::string const& s, std::string const& h)
79 : UCIengineCommand(s, h)
80 {}
82 {}
83};
84
85/**
86 * Sub-class to react uniformly on Xboard v1 interface specific stuff
87 */
89public:
90 Xboard1engineCommand(std::string const& s, std::string const& h)
91 : engineUserCommand(s, h)
92 {}
94 {}
95};
96
97/**
98 * Sub-class to react uniformly on Xboard v2 interface specific stuff
99 */
101public:
102 Xboard2engineCommand(std::string const& s, std::string const& h)
103 : engineUserCommand(s, h)
104 {}
106 {}
107};
108
109/**
110 * Do not react to command
111 */
113public:
114 dummyEngineCommand(std::string const& s, std::string const& h)
115 : engineUserCommand(s, h)
116 { m_isImplemented = false; }
118 {}
119
120 void execute(std::string const& args UNUSED) override {}
121};
122
123//-----------------------------------------------------------------------
124
125/**
126 * implementation of single command
127 */
129public:
130 cmd_help() : engineUserCommand("help", "show help, ['command'] [--all/all] [unsupported] [hidden] for more complete lists")
131 {}
132 void execute(std::string const& args) override;
133};
134
136public:
137 cmd_quit() : engineUserCommand("quit", "exit application")
138 {}
139 void execute(std::string const& args) override;
140};
141
143public:
144 cmd_echo() : engineUserCommand("echo", "print line, mainly for batch operation")
145 {}
146 void execute(std::string const& args) override;
147};
148
150public:
151 cmd_belofte() : engineUserCommand("belofte", "go back to belofte mode")
152 {}
153 void execute(std::string const& args) override;
154};
155
157public:
158 cmd_uci() : engineUserCommand("uci", "go to uci mode")
159 {}
160 void execute(std::string const& args) override;
161};
162
164public:
165 cmd_xboard() : engineUserCommand("xboard", "go to xboard mode")
166 {}
167 void execute(std::string const& args) override;
168};
169
171public:
172 cmd_setoption() : UCIengineCommand("setoption", "set various options")
173 {}
174 void execute(std::string const& args) override;
175};
176
178public:
179 cmd_isready() : UCIengineCommand("isready", "ask program if ready")
180 {}
181 void execute(std::string const& args) override;
182};
183
185public:
186 cmd_position() : UCIengineCommand("position", "set-up board")
187 {}
188 void execute(std::string const& args) override;
189};
190
191class cmd_go : public UCIengineCommand {
192public:
193 cmd_go() : UCIengineCommand("go", "start searching uci: [wtime ms btime ms winc ms binc ms movestogo n]")
194 {}
195 void execute(std::string const& args) override;
196};
197
199public:
200 cmd_stop() : engineUserCommand("stop", "stop searching")
201 {}
202 void execute(std::string const& args) override;
203};
204
206public:
207 cmd_ponderhit() : dummyEngineCommand("ponderhit", "start search from ponderhit")
208 {}
209};
210
212public:
213 cmd_ucinewgame() : UCIengineCommand("ucinewgame", "initialize new game")
214 {}
215 void execute(std::string const& args) override;
216};
217
219public:
220 cmd_exit() : Xboard2engineCommand("exit", "exit analyze mode")
221 {}
222};
223
225public:
226 cmd_debug() : engineUserCommand("debug", "various debug commands, type 'debug help' for more information")
227 {}
228 void execute(std::string const& args) override;
229};
230
232public:
233 cmd_bench() : engineUserCommand("bench", "run bench command")
234 {}
235 void execute(std::string const& args) override;
236};
237
239public:
240 cmd_perft() : engineUserCommand("perft", "run perft command")
241 {}
242 void execute(std::string const& args) override;
243};
244
246public:
247 cmd_epd() : engineUserCommand("epd", "file|pos [-sts|-perf] parse epd file or position")
248 {}
249 void execute(std::string const& args) override;
250};
251
252/**
253 * Parse epd position
254 * @note use `epd pos` instead (with space)
255 */
257public:
258 cmd_epdpos() : engineUserCommand("epdpos", "parse epd position (deprecated)")
259 {}
260 void execute(std::string const& args) override;
261};
262
263class cmd_ls : public engineUserCommand {
264public:
265 cmd_ls() : engineUserCommand("ls", "[pattern|subdir/] list content of directory")
266 {}
267 void execute(std::string const& args) override;
268};
269
271public:
272 cmd_execat() : engineUserCommand("@", "execute command file")
273 {}
274 void execute(std::string const& args) override;
275};
276
278public:
279 cmd_exec() : engineUserCommand("exec", "execute command file (alternative to @)")
280 {}
281 void execute(std::string const& args) override;
282};
283
285public:
286 cmd_about() : engineUserCommand("about", "prints about message")
287 {}
288 void execute(std::string const& args) override;
289};
290
292public:
293 cmd_export() : dummyEngineCommand("export", "export in standard PGN format")
294 {}
295};
296
298public:
299 cmd_save() : engineUserCommand("save", "save game and all game information "
300 "(extended PGN)")
301 {}
302 void execute(std::string const& args) override;
303};
304
306public:
307 cmd_game() : engineUserCommand("game", "display game and all game information "
308 "(extended PGN)")
309 {}
310 void execute(std::string const& args) override;
311};
312
313class cmd_bd : public engineUserCommand {
314public:
315 cmd_bd() : engineUserCommand("bd", "show board")
316 {}
317 void execute(std::string const& args) override;
318};
319
321public:
322 cmd_undo() : Xboard2engineCommand("undo", "undo last move, switches colour player to move")
323 {}
324 void execute(std::string const& args) override;
325};
326
328public:
329 cmd_usage() : engineUserCommand("usage", "shows how to call the application")
330 {}
331 void execute(std::string const& args) override;
332};
333
335public:
336 cmd_expect() : engineUserCommand("expect", "run next command in expect mode")
337 {}
338 void execute(std::string const& args) override;
339};
340
342public:
343 cmd_new() : Xboard2engineCommand("new", "new game")
344 {}
345 void execute(std::string const& args) override;
346};
347
349public:
350 cmd_setboard() : Xboard2engineCommand("setboard", "configure board")
351 {}
352 void execute(std::string const& args) override;
353};
354
356public:
357 cmd_usermove() : Xboard2engineCommand("usermove", "apply coordmove to position")
358 {}
359 void execute(std::string const& args) override;
360};
361
363public:
364 cmd_remove() : Xboard2engineCommand("remove", "undo last 2 moves")
365 {}
366 void execute(std::string const& args) override;
367};
368
370public:
371 cmd_again() : engineUserCommand("again", "undo move and search again")
372 {}
373 void execute(std::string const& args) override;
374};
375
377public:
378 cmd_protover() : Xboard2engineCommand("protover", "switch to xboard v2 mode")
379 {}
380 void execute(std::string const& args) override;
381};
382
384public:
385 cmd_accepted() : dummyEngineCommand("accepted", "notify acceptance of feature")
386 {}
387};
388
390public:
391 cmd_rejected() : dummyEngineCommand("rejected", "reject acceptance of feature")
392 {}
393};
394
396public:
397 cmd_option() : Xboard2engineCommand("option", "allow to set various options eg. option alg=AB")
398 {}
399 void execute(std::string const& args) override;
400};
401
403public:
404 cmd_playother() : Xboard2engineCommand("playother", "start engine for opponent side")
405 {}
406 void execute(std::string const& args) override;
407};
408
410public:
411 cmd_force() : Xboard2engineCommand("force", "stop engine for both sides")
412 {}
413 void execute(std::string const& args) override;
414};
415
417public:
418 cmd_level() : Xboard2engineCommand("level", "set level: moves time[:sec] increment")
419 {}
420 void execute(std::string const& args) override;
421};
422
424public:
425 cmd_sd() : Xboard2engineCommand("sd", "set depth")
426 {}
427 void execute(std::string const& args) override;
428};
429
431public:
432 cmd_fd() : Xboard2engineCommand("fd", "set fixed depth (e.g. mate in x)")
433 {}
434 void execute(std::string const& args) override;
435};
436
438public:
439 cmd_st() : Xboard2engineCommand("st", "set exact time per move")
440 {}
441 void execute(std::string const& args) override;
442};
443
445public:
446 cmd_time() : Xboard2engineCommand("time", "set remaining time")
447 {}
448 void execute(std::string const& args) override;
449};
450
452public:
453 cmd_otim() : dummyEngineCommand("otim", "set remaining time opponent")
454 {}
455};
456
458public:
459 cmd_ping() : Xboard2engineCommand("ping", "keep alive message")
460 {}
461 void execute(std::string const& args) override;
462};
463
465public:
466 cmd_post() : Xboard2engineCommand("post", "activate search output")
467 {}
468 void execute(std::string const& args) override;
469};
470
472public:
473 cmd_nopost() : Xboard2engineCommand("nopost", "deactivate search output")
474 {}
475 void execute(std::string const& args) override;
476};
477
479public:
480 cmd_easy() : Xboard1engineCommand("easy", "set ponder off")
481 {}
482 void execute(std::string const& args) override;
483};
484
486public:
487 cmd_hard() : Xboard1engineCommand("hard", "set ponder on (unsupported)")
488 {}
489 void execute(std::string const& args) override;
490};
491
493public:
494 cmd_random() : Xboard2engineCommand("random", "toggle random mode")
495 {}
496 void execute(std::string const& args) override;
497};
498
500public:
501 cmd_computer() : Xboard1engineCommand("computer", "indicate opponent is computer")
502 {}
503 void execute(std::string const& args) override;
504};
505
507public:
508 cmd_questionmark() : Xboard2engineCommand("?", "stop searching")
509 {}
510 void execute(std::string const& args) override;
511};
512
514public:
515 /// @note white command is only valid for winboard 1 modes
516 cmd_white() : dummyEngineCommand("white", "white to move, engine plays "
517 "black, stops clocks")
518 {}
519};
520
522public:
523 /// @note black command is only valid for winboard 1 modes
524 cmd_black() : dummyEngineCommand("black", "black to move, engine plays "
525 "white, stops clocks")
526 {}
527};
528
530public:
531 cmd_dot() : dummyEngineCommand(".", "end edit command")
532 {}
533};
534
536public:
537 cmd_result() : dummyEngineCommand("result", "inform engine of result")
538 {}
539};
540
542public:
543 /// @todo get values dynamically
545 "set algorithm: Random|StaticEval|BruteForce|SearchIterativeBF|"
546 "AB|ABFS|ABFH")
547 {}
548 void execute(std::string const& args) override;
549};
550
552public:
554 "give name of opponent")
555 {}
556 void execute(std::string const& args) override;
557};
558
560public:
562 "return info about engine")
563 {}
564 void execute(std::string const& args) override;
565};
566
568public:
570 "give name of opponent")
571 {}
572 void execute(std::string const& args) override;
573};
574
576public:
577 cmd_info() : engineUserCommand("info", "print info on program")
578 {}
579 void execute(std::string const& args) override;
580};
581
583public:
584 /// @todo get values dynamically
586 "set evaluation type: None|PiecesOnly|StaticBoard|PositionalBoard")
587 {}
588 void execute(std::string const& args) override;
589};
590
592public:
593 cmd_eval() : engineUserCommand("eval", "return position evaluation")
594 {}
595 void execute(std::string const& args) override;
596};
597
598#endif // defined USERCMD_H
599
600// eof
UCIengineCommand(std::string const &s, std::string const &h)
Definition usercmd.h:69
~UCIengineCommand() override
Definition usercmd.h:72
~UCIengineOption() override
Definition usercmd.h:81
UCIengineOption(std::string const &s, std::string const &h)
Definition usercmd.h:78
~Xboard1engineCommand() override
Definition usercmd.h:93
Xboard1engineCommand(std::string const &s, std::string const &h)
Definition usercmd.h:90
~Xboard2engineCommand() override
Definition usercmd.h:105
Xboard2engineCommand(std::string const &s, std::string const &h)
Definition usercmd.h:102
void execute(std::string const &args) override
Definition usercmd.cpp:544
void execute(std::string const &args) override
Definition usercmd.cpp:548
void execute(std::string const &args) override
Definition usercmd.cpp:33
cmd_about()
Definition usercmd.h:286
void execute(std::string const &args) override
Definition usercmd.cpp:371
cmd_again()
Definition usercmd.h:371
cmd_alg()
Definition usercmd.h:544
void execute(std::string const &args) override
Definition usercmd.cpp:534
void execute(std::string const &args) override
Definition usercmd.cpp:421
cmd_bd()
Definition usercmd.h:315
void execute(std::string const &args) override
Definition usercmd.cpp:82
cmd_bench()
Definition usercmd.h:233
void execute(std::string const &args) override
Definition usercmd.cpp:208
cmd_black()
Definition usercmd.h:524
void execute(std::string const &args) override
Definition usercmd.cpp:488
cmd_debug()
Definition usercmd.h:226
void execute(std::string const &args) override
Definition usercmd.cpp:140
cmd_dot()
Definition usercmd.h:531
cmd_easy()
Definition usercmd.h:480
void execute(std::string const &args) override
Definition usercmd.cpp:433
cmd_echo()
Definition usercmd.h:144
void execute(std::string const &args) override
Definition usercmd.cpp:111
cmd_epd()
Definition usercmd.h:247
void execute(std::string const &args) override
Parse epd position or epd file e.g.
Definition usercmd.cpp:270
void execute(std::string const &args) override
Parse epd position e.g.
Definition usercmd.cpp:310
void execute(std::string const &args) override
Definition usercmd.cpp:583
cmd_eval()
Definition usercmd.h:593
void execute(std::string const &args) override
Definition usercmd.cpp:539
void execute(std::string const &args) override
execute command file with exec command
Definition usercmd.cpp:106
cmd_exec()
Definition usercmd.h:279
void execute(std::string const &args) override
execute command file with @ command
Definition usercmd.cpp:92
cmd_exit()
Definition usercmd.h:220
void execute(std::string const &args) override
Definition usercmd.cpp:465
void execute(std::string const &args) override
Definition usercmd.cpp:637
cmd_fd()
Definition usercmd.h:432
cmd_force()
Definition usercmd.h:411
void execute(std::string const &args) override
Definition usercmd.cpp:529
void execute(std::string const &args) override
Definition usercmd.cpp:415
cmd_game()
Definition usercmd.h:307
void execute(std::string const &args) override
Definition usercmd.cpp:316
cmd_go()
Definition usercmd.h:193
void execute(std::string const &args) override
Definition usercmd.cpp:438
cmd_hard()
Definition usercmd.h:487
void execute(std::string const &args) override
Definition usercmd.cpp:21
cmd_help()
Definition usercmd.h:130
cmd_info()
Definition usercmd.h:577
void execute(std::string const &args) override
Definition usercmd.cpp:578
void execute(std::string const &args) override
check if engine still alive, doing delayed constructors
Definition usercmd.cpp:119
cmd_level()
Definition usercmd.h:418
void execute(std::string const &args) override
Definition usercmd.cpp:642
void execute(std::string const &args) override
Definition usercmd.cpp:443
cmd_ls()
Definition usercmd.h:265
void execute(std::string const &args) override
Definition usercmd.cpp:554
cmd_name()
Definition usercmd.h:569
void execute(std::string const &args) override
Definition usercmd.cpp:470
cmd_new()
Definition usercmd.h:343
void execute(std::string const &args) override
Definition usercmd.cpp:696
void execute(std::string const &args) override
Definition usercmd.cpp:560
cmd_otim()
Definition usercmd.h:453
cmd_perft()
Definition usercmd.h:240
void execute(std::string const &args) override
Definition usercmd.cpp:225
void execute(std::string const &args) override
check if engine still alive, doing delayed constructors
Definition usercmd.cpp:128
cmd_ping()
Definition usercmd.h:459
void execute(std::string const &args) override
Definition usercmd.cpp:524
void execute(std::string const &args) override
set start position, alternatives args = [fen 'fenstring' | startpos ] moves 'move1' ....
Definition usercmd.cpp:185
cmd_post()
Definition usercmd.h:466
void execute(std::string const &args) override
Definition usercmd.cpp:691
void execute(std::string const &args) override
Definition usercmd.cpp:499
void execute(std::string const &args) override
Definition usercmd.cpp:399
void execute(std::string const &args) override
Definition usercmd.cpp:26
cmd_quit()
Definition usercmd.h:137
void execute(std::string const &args) override
Definition usercmd.cpp:482
void execute(std::string const &args) override
Definition usercmd.cpp:493
void execute(std::string const &args) override
Definition usercmd.cpp:409
cmd_save()
Definition usercmd.h:299
void execute(std::string const &args) override
Definition usercmd.cpp:632
cmd_sd()
Definition usercmd.h:425
void execute(std::string const &args) override
Definition usercmd.cpp:477
void execute(std::string const &args) override
Read setoption command.
Definition usercmd.cpp:149
cmd_st()
Definition usercmd.h:439
void execute(std::string const &args) override
Definition usercmd.cpp:680
void execute(std::string const &args) override
Definition usercmd.cpp:404
cmd_stop()
Definition usercmd.h:200
void execute(std::string const &args) override
Definition usercmd.cpp:685
cmd_time()
Definition usercmd.h:446
cmd_uci()
Definition usercmd.h:158
void execute(std::string const &args) override
Definition usercmd.cpp:51
void execute(std::string const &args) override
Definition usercmd.cpp:133
cmd_undo()
Definition usercmd.h:322
void execute(std::string const &args) override
Definition usercmd.cpp:428
void execute(std::string const &args) override
Definition usercmd.cpp:40
cmd_usage()
Definition usercmd.h:329
void execute(std::string const &args) override
Definition usercmd.cpp:377
cmd_white()
Definition usercmd.h:516
void execute(std::string const &args) override
Definition usercmd.cpp:76
cmdParam & operator=(cmdParam const &)=delete
~cmdParam()
Definition usercmd.h:47
cmdParam(cmdParam const &)=delete
cmdParam(cmdParam &&)=default
cmdParam()
Definition usercmd.h:43
std::string m_command
Definition usercmd.h:58
cmdParam & operator=(cmdParam &&)=delete
std::string m_args
Definition usercmd.h:59
~dummyEngineCommand() override
Definition usercmd.h:117
dummyEngineCommand(std::string const &s, std::string const &h)
Definition usercmd.h:114
void execute(std::string const &args UNUSED) override
Definition usercmd.h:120
std::string m_hint
Definition usercmd.h:33
engineUserCommand & operator=(engineUserCommand const &)=delete
engineUserCommand & operator=(engineUserCommand &&)=delete
virtual ~engineUserCommand()
Definition usercmd.h:20
virtual void execute(std::string const &args)
Definition usercmd.cpp:12
engineUserCommand(engineUserCommand &&)=delete
std::string m_name
Definition usercmd.h:32
engineUserCommand(std::string const &s, std::string const &h)
Definition usercmd.h:16
engineUserCommand(engineUserCommand const &)=delete
bool m_isImplemented
Definition usercmd.h:34