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.
16 #include <boost/weak_ptr.hpp>
18 #include <core/state_fwd.h>
25 * @brief An external chess engine.
27 * This class incapsulates a connection with
28 * an external engine process in a protocol
31 class Engine
: public QObject
, public TextNotifier
{
35 QStringList m_arguments
;
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;
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
; }
55 * Start the engine program. The initialization will
56 * take place automatically after the program has started.
61 * Send a command to the engine.
63 void sendCommand(const QString
& command
, bool echo
= true);
66 * Send a move to the engine.
68 virtual void sendMove(const Move
& move
, const StatePtr
& ref
) = 0;
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;
85 virtual void reset() = 0;
90 virtual void play() = 0;
95 virtual void stop() = 0;
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
);
105 void engineRunning();
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();