Belofte version 2.2.0
A promising chess program using the UCI or Winboard interface
game.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: game.h
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#if !defined(GAME_H)
9#define GAME_H
10
11//-----------------------------------------------------------------------
12// helpers for bGame class
13
14typedef std::map<std::string, std::string> gameAttributes_t;
15typedef std::vector<bBoard> positions_t;
16
17//-----------------------------------------------------------------------
18
19/** game representation, singleton */
20class bGame : public bConfigurableGame {
21public:
22 bGame();
23 ~bGame() override
24 {}
25
26 bGame(bGame const&) = delete;
27 bGame(bGame&&) = delete;
28 bGame& operator=(bGame const&) = delete;
29 bGame& operator=(bGame&&) = delete;
30
31 void newGame();
32 void setFEN(std::string const& fenstr);
33 void setFENInitialPos();
34
35 bool playGameMoveSeries(std::string const& coordmoves);
36 bool playPGNMoves(std::string const& sPGNMoveList);
37 void revertGameMove(std::string const& reason);
38
39 static std::string getResult(gameResult_t gr);
40 void setResult(gameResult_t gr);
42 { return m_result; }
43
44 bool isExpecting(std::string const& s) const
45 { /// @todo improve by redirecting App().bout
46 return (m_expecting == "" || m_expecting == s); }
47 void setExpecting(std::string const& s)
48 { m_expecting = s; }
49 std::string const& getExpecting() const
50 { return m_expecting; }
51
52 /// @todo check why copy constructor is called, check if we should return
53 /// anything else but positions.back()
55 { return m_positions.back(); }
56
57 void setLevel(bLevel const& l)
58 { m_level = l; }
60 { return m_level; }
62 { return m_positions; }
63 void setPlayerName(std::string const& n);
64
65 void DoSearch();
66 void AbortSearch();
67 void WaitForSearchEnd();
68
70
71 // test related elements
72 int64_t DoPerftCommand(depth_t const d);
73 int64_t DoPerft(bSearchAlgorithm& sa, depth_t const d);
75
76 inline void setStandardPgn(bool const l)
77 { standardPGN = l; }
78 constexpr bool isStandardPgn() const
79 { return standardPGN; }
80 inline void setSearching(bool const l)
81 { isInSearch = l; }
82 constexpr bool isSearching() const
83 { return isInSearch; }
84
85 operator std::string() const;
86
87private:
88 bool playGameMove(bCoordMove const& coordmove);
89 std::string movesinpgnformat() const;
90
91 bool standardPGN = true;
92 bool isInSearch = false;
93 gameResult_t m_result = gameResult::GR_UNKNOWN; /// @todo move to last position
94 gameAttributes_t m_pgnTags;
95 gameAttributes_t m_optTags;
96 positions_t m_positions; /// @todo convert to class bPositions
97 bLevel m_level;
98 std::string m_expecting; // next command should return according to expectation
99};
100
101#endif // defined GAME_H
102
103// eof
int_fast8_t depth_t
Definition belofte.h:106
board
Definition board.h:45
simple coordmove, with 4 characters, or 5 characters in case of promotion mostly used for interface
Definition coordmove.h:15
FEN string.
Definition fen.h:14
std::string const & getExpecting() const
Definition game.h:49
bMove getEpdMoveInPosition(bFen const &fen)
do actual epd position test
Definition game.cpp:300
void setResult(gameResult_t gr)
Definition game.cpp:187
void setPlayerName(std::string const &n)
Definition game.cpp:62
constexpr bool isStandardPgn() const
Definition game.h:78
int64_t DoPerft(bSearchAlgorithm &sa, depth_t const d)
do perft search at depth in case of Perft algorithm, temporarily set evaltype to None
Definition game.cpp:139
bGame(bGame &&)=delete
void WaitForSearchEnd()
Called in separate thread, sure to terminate normally.
Definition game.cpp:106
void setExpecting(std::string const &s)
Definition game.h:47
bGame & operator=(bGame const &)=delete
void setStandardPgn(bool const l)
Definition game.h:76
bool playPGNMoves(std::string const &sPGNMoveList)
apply move, it will change the current board by updating the move played it will also add the new boa...
Definition game.cpp:248
void AbortSearch()
Definition game.cpp:98
constexpr bool isSearching() const
Definition game.h:82
positions_t & getPositions()
Definition game.h:61
void newGame()
Definition game.cpp:24
void revertGameMove(std::string const &reason)
required for Winboard protocol, not supported in UCI (except debug)
Definition game.cpp:286
bLevel & getLevel()
Definition game.h:59
void DoSearch()
Start search thread and exit in case of batch mode, will wait until end of search.
Definition game.cpp:75
bGame()
Definition game.cpp:15
bool playGameMoveSeries(std::string const &coordmoves)
all moves in a single string
Definition game.cpp:197
void setSearching(bool const l)
Definition game.h:80
bGame & operator=(bGame &&)=delete
void setFEN(std::string const &fenstr)
Definition game.cpp:54
int64_t DoPerftCommand(depth_t const d)
do perft search using SearchPerft algorithm at depth
Definition game.cpp:129
gameResult_t getResult() const
Definition game.h:41
bGame(bGame const &)=delete
bScore EvalForPlayer(bBoard const &b, gameResult_t gr)
Definition game.cpp:174
~bGame() override
Definition game.h:23
bBoard & getCurrentPosition()
Definition game.h:54
bool isExpecting(std::string const &s) const
Definition game.h:44
void setLevel(bLevel const &l)
Definition game.h:57
void setFENInitialPos()
Definition game.cpp:46
Definition level.h:48
Definition move.h:13
@ GR_UNKNOWN
Definition eval.h:33
enum gameResult gameResult_t
Definition eval.h:40
int16_t bScore
Definition eval.h:11
std::vector< bBoard > positions_t
Definition game.h:15
std::map< std::string, std::string > gameAttributes_t
Definition game.h:14