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
;
43 virtual void initializeEngine() = 0;
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
; }
57 * Start the engine program. The initialization will
58 * take place automatically after the program has started.
63 * Send a command to the engine.
65 void sendCommand(const QString
& command
, bool echo
= true);
68 * Send a move to the engine.
70 virtual void sendMove(const Move
& move
, const StatePtr
& ref
) = 0;
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;
87 virtual void reset() = 0;
92 virtual void play() = 0;
97 virtual void stop() = 0;
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
);
107 void engineRunning();
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();