Renamed AnimationSettings -> AnimationManager.
[tagua/yd.git] / src / engine.h
blobad7d2606a7a4b6d48f37fbccebbb9f9b88454e3b
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 ENGINE_H
12 #define ENGINE_H
14 #include <KProcess>
16 #include <boost/weak_ptr.hpp>
17 #include <queue>
18 #include <core/state_fwd.h>
19 #include "console.h"
21 class Move;
22 class EngineNotifier;
24 /**
25 * @brief An external chess engine.
27 * This class incapsulates a connection with
28 * an external engine process in a protocol
29 * independent way.
31 class Engine : public QObject, public TextNotifier {
32 Q_OBJECT
33 protected:
34 QString m_path;
35 QStringList m_arguments;
36 KProcess m_engine;
37 QString m_workPath;
38 boost::shared_ptr<Console> m_console;
39 boost::weak_ptr<EngineNotifier> m_notifier;
40 std::queue<QString> m_command_queue;
42 virtual void initializeEngine() = 0;
43 public:
44 /**
45 * Create an engine, setting the path to the engine
46 * program and its arguments.
48 Engine(const QString& path, const QStringList& arguments);
50 void setWorkingPath(const QString& workPath) { m_workPath = workPath; }
52 virtual ~Engine();
54 /**
55 * Start the engine program. The initialization will
56 * take place automatically after the program has started.
58 void start();
60 /**
61 * Send a command to the engine.
63 void sendCommand(const QString& command, bool echo = true);
65 /**
66 * Send a move to the engine.
68 virtual void sendMove(const Move& move, const StatePtr& ref) = 0;
70 /**
71 * Back up a move.
72 * @param pos The position before the move. Used if the engine
73 * does not support the undo command.
75 virtual void backUp(const StatePtr& pos) = 0;
77 virtual void setBoard(const StatePtr& pos) = 0;
79 virtual void startAnalysis() = 0;
80 virtual void stopAnalysis() = 0;
82 /**
83 * Begin a new game.
85 virtual void reset() = 0;
87 /**
88 * Start playing.
90 virtual void play() = 0;
92 /**
93 * Stop the engine.
95 virtual void stop() = 0;
97 /**
98 * Receive a user command.
100 virtual void textNotify(const QString& text);
102 void setNotifier(const boost::shared_ptr<EngineNotifier>& notifier);
103 void setConsole(const boost::shared_ptr<Console>& console);
104 private Q_SLOTS:
105 void engineRunning();
106 void processInput();
108 Q_SIGNALS:
111 * Emitted when the engine sends a command to the interface.
113 void receivedCommand(const QString& command);
116 * Emitted when the engine exits (or crashes, etc...).
118 void lostConnection();
121 #endif // ENGINE_H