Add finer engine tracing.
[tagua/yd.git] / src / engine.h
blobb81c46e622070146839fda9e147dab1cfa54dbe7
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>
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;
42 int m_side;
44 virtual void initializeEngine() = 0;
45 public:
46 /**
47 * Create an engine, setting the path to the engine
48 * program and its arguments.
50 Engine(const QString& path, const QStringList& arguments);
52 void setWorkingPath(const QString& workPath) { m_workPath = workPath; }
53 void setSide(int side) { m_side = side; }
55 virtual ~Engine();
57 /**
58 * Start the engine program. The initialization will
59 * take place automatically after the program has started.
61 void start();
63 /**
64 * Send a command to the engine.
66 void sendCommand(const QString& command, bool echo = true);
68 /**
69 * Send a move to the engine.
71 virtual void sendMove(AbstractMove::Ptr move, AbstractPosition::Ptr ref) = 0;
73 /**
74 * Back up a move.
75 * @param pos The position before the move. Used if the engine
76 * does not support the undo command.
78 virtual void backUp(AbstractPosition::Ptr pos) = 0;
80 virtual void setBoard(AbstractPosition::Ptr pos, int halfmove, int fullmove) = 0;
82 virtual void startAnalysis() = 0;
83 virtual void stopAnalysis() = 0;
85 /**
86 * Begin a new game.
88 virtual void reset() = 0;
90 /**
91 * Start playing.
93 virtual void play() = 0;
95 /**
96 * Stop the engine.
98 virtual void stop() = 0;
101 * Receive a user command.
103 virtual void textNotify(const QString& text);
105 void setNotifier(const boost::shared_ptr<EngineNotifier>& notifier);
106 void setConsole(const boost::shared_ptr<Console>& console);
107 private Q_SLOTS:
108 void engineRunning();
109 void processInput();
111 Q_SIGNALS:
114 * Emitted when the engine sends a command to the interface.
116 void receivedCommand(const QString& command);
119 * Emitted when the engine exits (or crashes, etc...).
121 void lostConnection();
124 #endif // ENGINE_H