Cute Chess 0.1
ChessPlayer Class Referenceabstract

A chess player, human or AI. More...

#include <chessplayer.h>

Inheritance diagram for ChessPlayer:
QObject ChessEngine HumanPlayer UciEngine XboardEngine

Public Types

enum  State {
  NotStarted , Starting , Idle , Observing ,
  Thinking , FinishingGame , Disconnected
}

Public Slots

virtual void go ()
virtual void kill ()
virtual void quit ()

Signals

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)

Public Member Functions

bool areClaimsValidated () const
 ChessPlayer (QObject *parent=nullptr)
virtual void clearPonderState ()
virtual void endGame (const Chess::Result &result)
QString errorString () const
const MoveEvaluationevaluation () const
bool hasError () const
virtual bool isHuman () const =0
virtual bool isReady () 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
virtual bool supportsVariant (const QString &variant) const =0
const TimeControltimeControl () const

Protected Slots

virtual void onCrashed ()
virtual void onTimeout ()

Protected Member Functions

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 startGame ()=0
virtual void startThinking ()=0

Protected Attributes

MoveEvaluation m_eval

Detailed Description

A chess player, human or AI.

See also
ChessEngine

Member Enumeration Documentation

◆ State

The different states of ChessPlayer.

Enumerator
NotStarted 

Not started or uninitialized.

Starting 

Starting or initializing.

Idle 

Idle and ready to start a game.

Observing 

Observing a game, or waiting for turn.

Thinking 

Thinking of the next move.

FinishingGame 

Finishing or cleaning up after a game.

Disconnected 

Disconnected or terminated.

Constructor & Destructor Documentation

◆ ChessPlayer()

ChessPlayer::ChessPlayer ( QObject * parent = nullptr)

Creates and initializes a new ChessPlayer object.

Member Function Documentation

◆ areClaimsValidated()

bool ChessPlayer::areClaimsValidated ( ) const

Returns true if result claims from the engine are validated; otherwise returns false.

With validation on (the default) the engine will forfeit the game if it makes an incorrect result claim.

◆ board()

Chess::Board * ChessPlayer::board ( )
protected

Returns the chessboard on which the player is playing.

◆ canPlayAfterTimeout()

bool ChessPlayer::canPlayAfterTimeout ( ) const
protectedvirtual

Returns true if this player can keep playing after running out of time; otherwise returns false.

◆ claimResult()

void ChessPlayer::claimResult ( const Chess::Result & result)
protected

Emits the resultClaim() signal with result result.

◆ clearPonderState()

void ChessPlayer::clearPonderState ( )
virtual

Clears the player's pondering state.

Reimplemented in UciEngine.

◆ debugMessage

void ChessPlayer::debugMessage ( const QString & data)
signal

Signals a debugging message from the player.

◆ disconnected

void ChessPlayer::disconnected ( )
signal

This signal is emitted when the player disconnects.

◆ emitMove()

void ChessPlayer::emitMove ( const Chess::Move & move)
protected

Emits the player's move, and a timeout signal if the move came too late.

◆ endGame()

void ChessPlayer::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 in ChessEngine, HumanPlayer, UciEngine, and XboardEngine.

◆ errorString()

QString ChessPlayer::errorString ( ) const

Returns a detailed description of the error.

◆ evaluation()

const MoveEvaluation & ChessPlayer::evaluation ( ) const

Returns the player's evaluation of the current position.

◆ forfeit()

void ChessPlayer::forfeit ( Chess::Result::Type type,
const QString & description = QString() )
protected

Emits the resultClaim() signal with a result of type type, description description, and this player as the loser.

◆ go

void ChessPlayer::go ( )
virtualslot

Waits (without blocking) until the player is ready, starts the chess clock, and tells the player to start thinking of the next move.

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

◆ hasError()

bool ChessPlayer::hasError ( ) const

Returns true if a parsing error occured.

◆ isHuman()

virtual bool ChessPlayer::isHuman ( ) const
pure virtual

Returns true if the player is human.

Implemented in ChessEngine, and HumanPlayer.

◆ isReady()

bool ChessPlayer::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 in ChessEngine.

◆ kill

void ChessPlayer::kill ( )
virtualslot

Kills the player process or connection, causing it to exit immediately.

The player's state is set to Disconnected.

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

◆ makeBookMove()

void ChessPlayer::makeBookMove ( const Chess::Move & move)
virtual

Forces the player to play move as its next move.

Reimplemented in UciEngine.

◆ makeMove()

virtual void ChessPlayer::makeMove ( const Chess::Move & move)
pure virtual

Sends the next move of an ongoing game to the player. If the player is in force/observer mode, the move wasn't necessarily made by the opponent.

Implemented in HumanPlayer, UciEngine, and XboardEngine.

◆ moveMade

void ChessPlayer::moveMade ( const Chess::Move & move)
signal

Signals the player's move.

◆ name()

QString ChessPlayer::name ( ) const

Returns the player's name.

◆ nameChanged

void ChessPlayer::nameChanged ( const QString & name)
signal

Emitted when player's name is changed.

◆ newGame()

void ChessPlayer::newGame ( Chess::Side side,
ChessPlayer * opponent,
Chess::Board * board )

Prepares the player for a new chess game, and then calls startGame() to start the game.

Parameters
sideThe side (color) the player should play as. It can be NoSide if the player is in force/observer mode.
opponentThe opposing player.
boardThe chessboard on which the game is played.
See also
startGame()

◆ onCrashed

void ChessPlayer::onCrashed ( )
protectedvirtualslot

Called when the player's process or connection crashes unexpectedly.

Forfeits the game.

◆ onTimeout

void ChessPlayer::onTimeout ( )
protectedvirtualslot

Called when the player's flag falls. Forfeits the game.

◆ opponent()

const ChessPlayer * ChessPlayer::opponent ( ) const
protected

Returns the opposing player.

◆ quit

void ChessPlayer::quit ( )
virtualslot

Terminates the player non-violently.

◆ ready

void ChessPlayer::ready ( )
signal

Signals that the player is ready for input.

◆ resultClaim

void ChessPlayer::resultClaim ( const Chess::Result & result)
signal

Emitted when the player claims the game to end with result result.

◆ setCanPlayAfterTimeout()

void ChessPlayer::setCanPlayAfterTimeout ( bool enable)

If enable is true the player will be allowed to continue the game after time is out, else the player will forfeit.

◆ setClaimsValidated()

void ChessPlayer::setClaimsValidated ( bool validate)

Sets result claim validation mode to validate.

◆ setError()

void ChessPlayer::setError ( const QString & error)
protected

Sets the current error to error.

◆ setName()

void ChessPlayer::setName ( const QString & name)

Sets the player's name.

◆ setState()

void ChessPlayer::setState ( State state)
protected

Sets the player's state to state.

◆ setTimeControl()

void ChessPlayer::setTimeControl ( const TimeControl & timeControl)

Sets the time control for the player.

◆ side()

Chess::Side ChessPlayer::side ( ) const

Returns the side of the player.

◆ startedThinking

void ChessPlayer::startedThinking ( int timeLeft)
signal

Signals the time left in the player's clock when they start thinking of their next move.

Parameters
timeLeftTime left in milliseconds.

◆ startGame()

virtual void ChessPlayer::startGame ( )
protectedpure virtual

Starts the chess game set up by newGame().

Implemented in ChessEngine, HumanPlayer, UciEngine, and XboardEngine.

◆ startPondering()

void ChessPlayer::startPondering ( )
virtual

Tells the player to start pondering (thinking on the opponent's move). The default implementation does nothing.

Reimplemented in UciEngine.

◆ startThinking()

virtual void ChessPlayer::startThinking ( )
protectedpure virtual

Tells the player to start thinking of the next move.

The player is guaranteed to be ready to move when this function is called by go().

Implemented in HumanPlayer, UciEngine, and XboardEngine.

◆ state()

ChessPlayer::State ChessPlayer::state ( ) const

Returns the player's state.

◆ stoppedThinking

void ChessPlayer::stoppedThinking ( )
signal

This signal is emitted when the player stops thinking of a move. Note that it doesn't necessarily mean that the player has made a move - they could've lost the game on time, disconnected, etc.

◆ supportsVariant()

virtual bool ChessPlayer::supportsVariant ( const QString & variant) const
pure virtual

Returns true if the player can play variant.

Implemented in ChessEngine, and HumanPlayer.

◆ thinking

void ChessPlayer::thinking ( const MoveEvaluation & eval)
signal

This signal is emitted when the player's evaluation of the current position changes.

◆ timeControl()

const TimeControl * ChessPlayer::timeControl ( ) const

Returns the player's time control.

Member Data Documentation

◆ m_eval

MoveEvaluation ChessPlayer::m_eval
protected

Move evaluation for the current move.

This move evaluation may have eval info from multiple search depths if the highest depth doesn't contain a complete evaluation.


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