Update for doxygen 1.5.5, graph generation, and match current code.
[tagua/yd.git] / src / engine.h
blob3fc6fc9cbf514b350f5dfde1ab61ac53bbadaa5e
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;
41 int m_side;
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; }
52 void setSide(int side) { m_side = side; }
54 virtual ~Engine();
56 /**
57 * Start the engine program. The initialization will
58 * take place automatically after the program has started.
60 void start();
62 /**
63 * Send a command to the engine.
65 void sendCommand(const QString& command, bool echo = true);
67 /**
68 * Send a move to the engine.
70 virtual void sendMove(const Move& move, const StatePtr& ref) = 0;
72 /**
73 * Back up a move.
74 * @param pos The position before the move. Used if the engine
75 * does not support the undo command.
77 virtual void backUp(const StatePtr& pos) = 0;
79 virtual void setBoard(const StatePtr& pos) = 0;
81 virtual void startAnalysis() = 0;
82 virtual void stopAnalysis() = 0;
84 /**
85 * Begin a new game.
87 virtual void reset() = 0;
89 /**
90 * Start playing.
92 virtual void play() = 0;
94 /**
95 * Stop the engine.
97 virtual void stop() = 0;
99 /**
100 * Receive a user command.
102 virtual void textNotify(const QString& text);
104 void setNotifier(const boost::shared_ptr<EngineNotifier>& notifier);
105 void setConsole(const boost::shared_ptr<Console>& console);
106 private Q_SLOTS:
107 void engineRunning();
108 void processInput();
110 Q_SIGNALS:
113 * Emitted when the engine sends a command to the interface.
115 void receivedCommand(const QString& command);
118 * Emitted when the engine exits (or crashes, etc...).
120 void lostConnection();
123 #endif // ENGINE_H