First steps at creating a taguacore library.
[tagua/yd.git] / src / xboardengine.h
blob643d99605f7560cf0cc7a29f4161559d3b9fcda2
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef XBOARDENGINE_H
12 #define XBOARDENGINE_H
14 #include "engine.h"
15 #include "tagua.h"
17 class QRegExp;
19 /**
20 * @brief A chess engine compatible with xboard.
22 * XBoard compatible engines are defined by Tim Mann's
23 * Chess Engine Communication Protocol (available at
24 * http://tim-mann.org/xboard/engine-intf.html), used
25 * by GNU Chess, Crafty and many other free and commercial
26 * chess engines.
27 * This class encapsulates such communication protocol,
28 * calling appropriate methods of the notifier upon engine
29 * generated events.
31 * @note This code is partially stolen from Maurizio Monge's
32 * old interface project outoftime.
34 class XBoardEngine : public Engine {
35 Q_OBJECT
36 struct Features {
37 bool ping : 1;
38 bool setboard : 1;
39 bool playother : 1;
40 bool san : 1;
41 bool usermove : 1;
42 bool time : 1;
43 bool draw : 1;
44 bool sigint : 1;
45 bool sigterm : 1;
46 bool reuse : 1;
47 bool analyze : 1;
48 QString myname;
49 QString variants;
50 bool colors : 1;
51 bool ics : 1;
52 bool name : 1;
53 bool pause : 1;
54 bool done : 1;
57 Features m_features;
58 bool m_analysing;
60 static QRegExp m_move_pattern;
61 protected:
62 /**
63 * Initialize the engine.
65 virtual void initializeEngine();
66 protected Q_SLOTS:
67 /**
68 * Parse engine command line and the appropriate
69 * signals.
71 void processCommand(const QString& command);
72 public:
73 /**
74 * Create an xboard compatible engine.
76 XBoardEngine(const QString& path, const QStringList& arguments);
78 /**
79 * Terminate the engine.
81 virtual ~XBoardEngine();
83 /**
84 * Send a move to the engine.
86 virtual void sendMove(AbstractMove::Ptr move, AbstractPosition::Ptr ref);
88 /**
89 * Back up a move.
90 * @param pos The position before the move. Used if the engine
91 * does not support the undo command.
93 virtual void backUp(AbstractPosition::Ptr pos);
95 virtual void setBoard(AbstractPosition::Ptr pos, int halfmove, int fullmove);
98 /**
99 * Begin a new game.
101 virtual void reset();
104 * Start playing.
106 virtual void play();
109 * Stop the engine.
111 virtual void stop();
113 virtual void startAnalysis();
114 virtual void stopAnalysis();
117 #endif // XBOARDENGINE_H