Cute Chess  0.1
uciengine.h
1 /*
2  This file is part of Cute Chess.
3 
4  Cute Chess is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  Cute Chess is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef UCIENGINE_H
19 #define UCIENGINE_H
20 
21 #include "chessengine.h"
22 #include <QVarLengthArray>
23 
24 
30 class LIB_EXPORT UciEngine : public ChessEngine
31 {
32  Q_OBJECT
33 
34  public:
36  UciEngine(QObject* parent = nullptr);
37 
38  // Inherited from ChessEngine
39  virtual void endGame(const Chess::Result& result);
40  virtual void makeMove(const Chess::Move& move);
41  virtual void makeBookMove(const Chess::Move& move);
42  virtual QString protocol() const;
43  virtual void startPondering();
44  virtual void clearPonderState();
45 
46  protected:
47  // Inherited from ChessEngine
48  virtual bool sendPing();
49  virtual void sendStop();
50  virtual void sendQuit();
51  virtual void startProtocol();
52  virtual void startGame();
53  virtual void startThinking();
54  virtual void parseLine(const QString& line);
55  virtual void sendOption(const QString& name, const QVariant& value);
56  virtual bool isPondering() const;
57 
58  private:
59  enum PonderState
60  {
61  NotPondering,
62  Pondering,
63  PonderHit
64  };
65 
66  static QStringRef parseUciTokens(const QStringRef& first,
67  const QString* types,
68  int typeCount,
70  int& type);
71  void parseInfo(const QVarLengthArray<QStringRef>& tokens,
72  int type,
73  MoveEvaluation* eval);
74  void parseInfo(const QStringRef& line);
75  EngineOption* parseOption(const QStringRef& line);
76  void addVariantsFromOption(const EngineOption* option);
77  void setVariant(const QString& variant);
78  QString positionString();
79  void sendPosition();
80  void setPonderMove(const QString& moveString);
81  QString directPv(const QVarLengthArray<QStringRef>& tokens);
82  QString sanPv(const QVarLengthArray<QStringRef>& tokens);
83 
84  QString m_variantOption;
85  QString m_startFen;
86  QString m_moveStrings;
87  bool m_useDirectPv;
88  // Write buffer for messages that will be flushed to the engine
89  // after it sends a "bestmove"
90  QStringList m_bmBuffer;
91  bool m_sendOpponentsName;
92  bool m_canPonder;
93  PonderState m_ponderState;
94  Chess::Move m_ponderMove;
95  QString m_ponderMoveSan;
96  int m_movesPondered;
97  int m_ponderHits;
98  bool m_ignoreThinking;
99  bool m_rePing;
100  MoveEvaluation m_currentEval;
101  QStringList m_comboVariants;
102 };
103 
104 #endif // UCIENGINE_H
virtual void sendQuit()=0
virtual void startPondering()
Definition: chessplayer.cpp:223
virtual void sendOption(const QString &name, const QVariant &value)=0
virtual bool isPondering() const
Definition: chessengine.cpp:264
Evaluation data for a chess move.
Definition: moveevaluation.h:35
virtual bool sendPing()=0
virtual void startThinking()=0
virtual void endGame(const Chess::Result &result)
Definition: chessengine.cpp:279
virtual void clearPonderState()
Definition: chessplayer.cpp:227
virtual void makeMove(const Chess::Move &move)=0
virtual QString protocol() const =0
virtual void sendStop()=0
virtual void makeBookMove(const Chess::Move &move)
Definition: chessplayer.cpp:137
An artificial intelligence chess player.
Definition: chessengine.h:41
The result of a chess game.
Definition: result.h:34
Definition: engineoption.h:25
A small and efficient chessmove class.
Definition: move.h:42
virtual void startGame()=0
A chess engine which uses the UCI chess interface.
Definition: uciengine.h:30
virtual void startProtocol()=0
virtual void parseLine(const QString &line)=0