Added real animations to the Shogi animator.
[tagua.git] / src / engine.h
blobf929c36cb1b6dc65954bf6715ed14753d159670a
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 <QProcess>
15 #include <boost/weak_ptr.hpp>
16 #include "console.h"
17 #include "kboard.h"
20 class EngineNotifier;
22 /**
23 * @brief An external chess engine.
25 * This class incapsulates a connection with
26 * an external engine process in a protocol
27 * independent way.
29 class Engine : public QObject, public TextNotifier {
30 Q_OBJECT
31 protected:
32 QString m_path;
33 QStringList m_arguments;
34 QProcess m_engine;
35 QString m_workPath;
36 boost::shared_ptr<Console> m_console;
37 boost::weak_ptr<EngineNotifier> m_notifier;
39 virtual void initializeEngine() = 0;
40 public:
41 /**
42 * Create an engine, setting the path to the engine
43 * program and its arguments.
45 Engine(const QString& path, const QStringList& arguments);
47 void setWorkingPath(const QString& workPath) { m_workPath = workPath; }
49 virtual ~Engine();
51 /**
52 * Start the engine program. The initialization will
53 * take place automatically after the program has started.
55 void start();
57 /**
58 * Send a command to the engine.
60 void sendCommand(const QString& command, bool echo = true);
62 /**
63 * Send a move to the engine.
64 */
65 virtual void sendMove(AbstractMove::Ptr move, AbstractPosition::Ptr ref) = 0;
67 /**
68 * Back up a move.
69 * @param pos The position before the move. Used if the engine
70 * does not support the undo command.
72 virtual void backUp(AbstractPosition::Ptr pos) = 0;
74 virtual void setBoard(AbstractPosition::Ptr pos, int halfmove, int fullmove) = 0;
76 virtual void startAnalysis() = 0;
77 virtual void stopAnalysis() = 0;
79 /**
80 * Begin a new game.
82 virtual void reset(int side) = 0;
84 /**
85 * Stop the engine.
87 virtual void stop() = 0;
89 /**
90 * Receive a user command.
92 virtual void textNotify(const QString& text);
94 void setNotifier(const boost::shared_ptr<EngineNotifier>& notifier);
95 void setConsole(const boost::shared_ptr<Console>& console);
96 private slots:
97 void processInput();
99 signals:
102 * Emitted when the engine sends a command to the interface.
104 void receivedCommand(const QString& command);
107 * Emitted when the engine exits (or crashes, etc...).
109 void lostConnection();
112 #endif // ENGINE_H