|
Cute Chess
0.1
|
An artificial intelligence chess player. More...
#include <chessengine.h>
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) | |
| QIODevice * | device () 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 MoveEvaluation & | evaluation () 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 TimeControl * | timeControl () 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 () |
| EngineOption * | getOption (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::Board * | board () |
| 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 ChessPlayer * | opponent () 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 |
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.
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. |
| ChessEngine::ChessEngine | ( | QObject * | parent = nullptr | ) |
Creates and initializes a new ChessEngine.
|
protected |
Adds option to the engine options list.
|
protected |
Adds variant to the list of supported variants.
| void ChessEngine::applyConfiguration | ( | const EngineConfiguration & | configuration | ) |
Applies configuration to the engine.
|
protected |
Clears the list of supported variants.
|
protectedslot |
Clear the write buffer without flushing it.
| QIODevice * ChessEngine::device | ( | ) | const |
Returns the current device associated with the engine.
|
virtual |
Tells the player that the game ended by result.
Reimplemented from ChessPlayer.
Reimplemented in UciEngine, and XboardEngine.
|
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.
|
protectedslot |
Flushes the write buffer. If there are any commands in the buffer, they will be sent to the engine.
|
protected |
Returns the option that matches name. Returns 0 if an option with that name doesn't exist.
|
virtual |
Returns true if the player is human.
Implements ChessPlayer.
|
protectedvirtual |
Returns true if the engine is currently thinking on the opponent's move; otherwise returns false.
Reimplemented in UciEngine.
|
virtual |
Returns true if the player is ready for input.
Reimplemented from ChessPlayer.
|
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.
|
protectedslot |
Called when the engine idles for too long.
|
protectedslot |
Called when the engine doesn't respond to ping.
|
protectedslot |
Called when the engine has started the chess protocol and is ready to start a game.
|
protectedslot |
Reads input from the engine.
| QList< EngineOption * > ChessEngine::options | ( | ) | const |
Returns a list of supported options and their values.
|
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.
|
protected |
Returns true if pondering is enabled for the engine; otherwise returns false.
|
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.
|
pure virtual |
Returns the engine's chess protocol.
Implemented in UciEngine, and XboardEngine.
|
protected |
Returns the restart mode. The default value is EngineConfiguration::RestartAuto.
|
protectedvirtual |
Returns true if the engine restarts between games; otherwise returns false.
Reimplemented in XboardEngine.
|
protectedpure virtual |
Tells the engine to set option name's value to value.
Implemented in UciEngine, and XboardEngine.
|
protectedpure virtual |
Sends a ping command to the engine. Returns true if successful; otherwise returns false.
Implemented in UciEngine, and XboardEngine.
|
protectedpure virtual |
Sends the quit command to the engine.
Implemented in UciEngine, and XboardEngine.
|
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.
Sets an option with the name name to value.
| void ChessEngine::start | ( | ) |
Starts communicating with the engine.
|
protectedpure virtual |
Starts the chess game set up by newGame().
Implements ChessPlayer.
Implemented in UciEngine, and XboardEngine.
|
protectedpure virtual |
Puts the engine in the correct mode to start communicating with it, using the chosen chess protocol.
Implemented in UciEngine, and XboardEngine.
|
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.
|
virtual |
Returns true if the player can play variant.
Implements ChessPlayer.
| QStringList ChessEngine::variants | ( | ) | const |
Returns a list of supported chess variants.
|
protected |
Are evaluation scores from white's point of view?
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.
1.8.11