Removed AlgebraicNotation from the variant API.
[tagua/yd.git] / src / engine.h
blob75dd7a81a5e9194fd2dc72fad228a6d1bd51b010
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
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 ENGINE_H
12 #define ENGINE_H
14 #include <KProcess>
16 #include <boost/weak_ptr.hpp>
17 #include <queue>
19 #include "console.h"
20 #include "tagua.h"
23 class EngineNotifier;
25 /**
26 * @brief An external chess engine.
28 * This class incapsulates a connection with
29 * an external engine process in a protocol
30 * independent way.
32 class Engine : public QObject, public TextNotifier {
33 Q_OBJECT
34 protected:
35 QString m_path;
36 QStringList m_arguments;
37 KProcess m_engine;
38 QString m_workPath;
39 boost::shared_ptr<Console> m_console;
40 boost::weak_ptr<EngineNotifier> m_notifier;
41 std::queue<QString> m_command_queue;
43 virtual void initializeEngine() = 0;
44 public:
45 /**
46 * Create an engine, setting the path to the engine
47 * program and its arguments.
49 Engine(const QString& path, const QStringList& arguments);
51 void setWorkingPath(const QString& workPath) { m_workPath = workPath; }
53 virtual ~Engine();
55 /**
56 * Start the engine program. The initialization will
57 * take place automatically after the program has started.
59 void start();
61 /**
62 * Send a command to the engine.
64 void sendCommand(const QString& command, bool echo = true);
66 /**
67 * Send a move to the engine.
69 virtual void sendMove(AbstractMove::Ptr move, AbstractPosition::Ptr ref) = 0;
71 /**
72 * Back up a move.
73 * @param pos The position before the move. Used if the engine
74 * does not support the undo command.
76 virtual void backUp(AbstractPosition::Ptr pos) = 0;
78 virtual void setBoard(AbstractPosition::Ptr pos, int halfmove, int fullmove) = 0;
80 virtual void startAnalysis() = 0;
81 virtual void stopAnalysis() = 0;
83 /**
84 * Begin a new game.
86 virtual void reset() = 0;
88 /**
89 * Start playing.
91 virtual void play() = 0;
93 /**
94 * Stop the engine.
96 virtual void stop() = 0;
98 /**
99 * Receive a user command.
101 virtual void textNotify(const QString& text);
103 void setNotifier(const boost::shared_ptr<EngineNotifier>& notifier);
104 void setConsole(const boost::shared_ptr<Console>& console);
105 private Q_SLOTS:
106 void engineRunning();
107 void processInput();
109 Q_SIGNALS:
112 * Emitted when the engine sends a command to the interface.
114 void receivedCommand(const QString& command);
117 * Emitted when the engine exits (or crashes, etc...).
119 void lostConnection();
122 #endif // ENGINE_H