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>
26 * @brief An external chess engine.
28 * This class incapsulates a connection with
29 * an external engine process in a protocol
32 class Engine
: public QObject
, public TextNotifier
{
36 QStringList m_arguments
;
39 boost::shared_ptr
<Console
> m_console
;
40 boost::weak_ptr
<EngineNotifier
> m_notifier
;
41 std::queue
<QString
> m_command_queue
;
44 virtual void initializeEngine() = 0;
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
; }
58 * Start the engine program. The initialization will
59 * take place automatically after the program has started.
64 * Send a command to the engine.
66 void sendCommand(const QString
& command
, bool echo
= true);
69 * Send a move to the engine.
71 virtual void sendMove(AbstractMove::Ptr move
, AbstractPosition::Ptr ref
) = 0;
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;
88 virtual void reset() = 0;
93 virtual void play() = 0;
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
);
108 void engineRunning();
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();