Cute Chess  0.1
Public Types | Public Slots | Public Member Functions | Protected Slots | Protected Member Functions | Static Protected Member Functions | List of all members
ChessEngine Class Referenceabstract

An artificial intelligence chess player. More...

#include <chessengine.h>

Inheritance diagram for ChessEngine:
ChessPlayer QObject UciEngine XboardEngine

Public Types

enum  WriteMode { Buffered, Unbuffered }
 
- Public Types inherited from ChessPlayer
enum  State {
  NotStarted, Starting, Idle, Observing,
  Thinking, FinishingGame, Disconnected
}
 

Public Slots

virtual void go ()
 
virtual void kill ()
 
virtual void quit ()
 
- Public Slots inherited from ChessPlayer
virtual void go ()
 
virtual void kill ()
 
virtual void quit ()
 

Public Member Functions

void applyConfiguration (const EngineConfiguration &configuration)
 
 ChessEngine (QObject *parent=nullptr)
 
QIODevicedevice () const
 
virtual void endGame (const Chess::Result &result)
 
virtual bool isHuman () const
 
virtual bool isReady () const
 
QList< EngineOption * > options () const
 
void ping (bool sendCommand=true)
 
virtual QString protocol () const =0
 
void setDevice (QIODevice *device)
 
void setOption (const QString &name, const QVariant &value)
 
void start ()
 
virtual bool supportsVariant (const QString &variant) const
 
QStringList variants () const
 
void write (const QString &data, WriteMode mode=Buffered)
 
- Public Member Functions inherited from ChessPlayer
bool areClaimsValidated () const
 
 ChessPlayer (QObject *parent=nullptr)
 
virtual void clearPonderState ()
 
QString errorString () const
 
const MoveEvaluationevaluation () const
 
bool hasError () const
 
virtual void makeBookMove (const Chess::Move &move)
 
virtual void makeMove (const Chess::Move &move)=0
 
QString name () const
 
void newGame (Chess::Side side, ChessPlayer *opponent, Chess::Board *board)
 
void setCanPlayAfterTimeout (bool enable)
 
void setClaimsValidated (bool validate)
 
void setName (const QString &name)
 
void setTimeControl (const TimeControl &timeControl)
 
Chess::Side side () const
 
virtual void startPondering ()
 
State state () const
 
const TimeControltimeControl () const
 

Protected Slots

void clearWriteBuffer ()
 
void flushWriteBuffer ()
 
void onIdleTimeout ()
 
void onPingTimeout ()
 
void onProtocolStart ()
 
void onReadyRead ()
 
virtual void onTimeout ()
 
void pong (bool emitReady=true)
 
- Protected Slots inherited from ChessPlayer
virtual void onCrashed ()
 
virtual void onTimeout ()
 

Protected Member Functions

void addOption (EngineOption *option)
 
void addVariant (const QString &variant)
 
void clearVariants ()
 
EngineOptiongetOption (const QString &name) const
 
virtual bool isPondering () const
 
virtual void parseLine (const QString &line)=0
 
bool pondering () const
 
EngineConfiguration::RestartMode restartMode () const
 
virtual bool restartsBetweenGames () const
 
virtual void sendOption (const QString &name, const QVariant &value)=0
 
virtual bool sendPing ()=0
 
virtual void sendQuit ()=0
 
virtual void sendStop ()=0
 
virtual void startGame ()=0
 
virtual void startProtocol ()=0
 
bool stopThinking ()
 
bool whiteEvalPov () const
 
- Protected Member Functions inherited from ChessPlayer
Chess::Boardboard ()
 
virtual bool canPlayAfterTimeout () const
 
void claimResult (const Chess::Result &result)
 
void emitMove (const Chess::Move &move)
 
void forfeit (Chess::Result::Type type, const QString &description=QString())
 
const ChessPlayeropponent () const
 
void setError (const QString &error)
 
void setState (State state)
 
virtual void startThinking ()=0
 

Static Protected Member Functions

static QStringRef firstToken (const QString &str, bool readToEnd=false)
 
static QStringRef nextToken (const QStringRef &previous, bool readToEnd=false)
 

Additional Inherited Members

- Signals inherited from ChessPlayer
void debugMessage (const QString &data)
 
void disconnected ()
 
void moveMade (const Chess::Move &move)
 
void nameChanged (const QString &name)
 
void ready ()
 
void resultClaim (const Chess::Result &result)
 
void startedThinking (int timeLeft)
 
void stoppedThinking ()
 
void thinking (const MoveEvaluation &eval)
 
- Protected Attributes inherited from ChessPlayer
MoveEvaluation m_eval
 

Detailed Description

An artificial intelligence chess player.

ChessEngine is a separate process (run locally or over a network) using either the Xboard or Uci chess protocol. Communication between the GUI and the chess engines happens via a QIODevice.

See also
XboardEngine
UciEngine

Member Enumeration Documentation

The write mode used by write() when the engine is being pinged. This doesn't affect the IO device's buffering.

Enumerator
Buffered 

Use the write buffer.

Unbuffered 

Bypass the write buffer.

Constructor & Destructor Documentation

ChessEngine::ChessEngine ( QObject parent = nullptr)

Creates and initializes a new ChessEngine.

Member Function Documentation

void ChessEngine::addOption ( EngineOption option)
protected

Adds option to the engine options list.

void ChessEngine::addVariant ( const QString variant)
protected

Adds variant to the list of supported variants.

void ChessEngine::applyConfiguration ( const EngineConfiguration configuration)

Applies configuration to the engine.

void ChessEngine::clearVariants ( )
protected

Clears the list of supported variants.

void ChessEngine::clearWriteBuffer ( )
protectedslot

Clear the write buffer without flushing it.

QIODevice * ChessEngine::device ( ) const

Returns the current device associated with the engine.

void ChessEngine::endGame ( const Chess::Result result)
virtual

Tells the player that the game ended by result.

Note
Subclasses that reimplement this function must call the base implementation.

Reimplemented from ChessPlayer.

Reimplemented in UciEngine, and XboardEngine.

QStringRef ChessEngine::firstToken ( const QString str,
bool  readToEnd = false 
)
staticprotected

Reads the first whitespace-delimited token from a string and returns a QStringRef reference to the token.

If readToEnd is true, the whole string is read, except for leading and trailing whitespace. Otherwise only one word is read.

If str doesn't contain any words, a null QStringRef object is returned.

void ChessEngine::flushWriteBuffer ( )
protectedslot

Flushes the write buffer. If there are any commands in the buffer, they will be sent to the engine.

EngineOption * ChessEngine::getOption ( const QString name) const
protected

Returns the option that matches name. Returns 0 if an option with that name doesn't exist.

bool ChessEngine::isHuman ( ) const
virtual

Returns true if the player is human.

Implements ChessPlayer.

bool ChessEngine::isPondering ( ) const
protectedvirtual

Returns true if the engine is currently thinking on the opponent's move; otherwise returns false.

Reimplemented in UciEngine.

bool ChessEngine::isReady ( ) const
virtual

Returns true if the player is ready for input.

Note
When the player's state is Disconnected, this function still returns true if all the cleanup following the disconnection is done.

Reimplemented from ChessPlayer.

QStringRef ChessEngine::nextToken ( const QStringRef previous,
bool  readToEnd = false 
)
staticprotected

Reads the first whitespace-delimited token after the token referenced by previous.

If readToEnd is true, everything from the first word after previous to the end of the string is read, except for leading and trailing whitespace. Otherwise only one word is read.

If previous is null or it's not followed by any words, a null QStringRef object is returned.

void ChessEngine::onIdleTimeout ( )
protectedslot

Called when the engine idles for too long.

void ChessEngine::onPingTimeout ( )
protectedslot

Called when the engine doesn't respond to ping.

void ChessEngine::onProtocolStart ( )
protectedslot

Called when the engine has started the chess protocol and is ready to start a game.

void ChessEngine::onReadyRead ( )
protectedslot

Reads input from the engine.

QList< EngineOption * > ChessEngine::options ( ) const

Returns a list of supported options and their values.

virtual void ChessEngine::parseLine ( const QString line)
protectedpure virtual

Parses a line of input from the engine.

Implemented in UciEngine, and XboardEngine.

void ChessEngine::ping ( bool  sendCommand = true)

Sends a ping message (an echo request) to the engine to check if it's still responding to input, and to synchronize it with the game operator. If the engine doesn't respond in reasonable time, it will be terminated.

if sendCommand is false, nothing is actually sent to the engine (but we'll pretend a message was sent); otherwise the ping message is sent.

Note
All input to the engine will be delayed until we get a response to the ping.
bool ChessEngine::pondering ( ) const
protected

Returns true if pondering is enabled for the engine; otherwise returns false.

Note
Even if pondering is enabled, it's still possible that the engine does not support pondering.
void ChessEngine::pong ( bool  emitReady = true)
protectedslot

Called when the engine responds to ping.

Does nothing if the engine is not being pinged. Flushes any pending output to the engine. If emitReady is true, the ready() signal is emitted after pending output is flushed.

virtual QString ChessEngine::protocol ( ) const
pure virtual

Returns the engine's chess protocol.

Implemented in UciEngine, and XboardEngine.

EngineConfiguration::RestartMode ChessEngine::restartMode ( ) const
protected

Returns the restart mode. The default value is EngineConfiguration::RestartAuto.

bool ChessEngine::restartsBetweenGames ( ) const
protectedvirtual

Returns true if the engine restarts between games; otherwise returns false.

Reimplemented in XboardEngine.

virtual void ChessEngine::sendOption ( const QString name,
const QVariant value 
)
protectedpure virtual

Tells the engine to set option name's value to value.

Implemented in UciEngine, and XboardEngine.

virtual bool ChessEngine::sendPing ( )
protectedpure virtual

Sends a ping command to the engine. Returns true if successful; otherwise returns false.

Implemented in UciEngine, and XboardEngine.

virtual void ChessEngine::sendQuit ( )
protectedpure virtual

Sends the quit command to the engine.

Implemented in UciEngine, and XboardEngine.

virtual void ChessEngine::sendStop ( )
protectedpure virtual

Sends the stop command to the engine.

Implemented in UciEngine, and XboardEngine.

void ChessEngine::setDevice ( QIODevice device)

Sets the current device to device.

void ChessEngine::setOption ( const QString name,
const QVariant value 
)

Sets an option with the name name to value.

Note
If the engine doesn't have an option called name, nothing happens.
void ChessEngine::start ( )

Starts communicating with the engine.

Note
The engine device must already be started.
virtual void ChessEngine::startGame ( )
protectedpure virtual

Starts the chess game set up by newGame().

Implements ChessPlayer.

Implemented in UciEngine, and XboardEngine.

virtual void ChessEngine::startProtocol ( )
protectedpure virtual

Puts the engine in the correct mode to start communicating with it, using the chosen chess protocol.

Implemented in UciEngine, and XboardEngine.

bool ChessEngine::stopThinking ( )
protected

Tells the engine to stop thinking and move now (if on move).

Returns true if the stop message was actually sent; otherwise returns false.

bool ChessEngine::supportsVariant ( const QString variant) const
virtual

Returns true if the player can play variant.

Implements ChessPlayer.

QStringList ChessEngine::variants ( ) const

Returns a list of supported chess variants.

bool ChessEngine::whiteEvalPov ( ) const
protected

Are evaluation scores from white's point of view?

void ChessEngine::write ( const QString data,
WriteMode  mode = Buffered 
)

Writes text data to the chess engine.

If mode is Unbuffered, the data will be written to the device immediately even if the engine is being pinged.


The documentation for this class was generated from the following files: