Belofte  version 2.1.5
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 
14 typedef std::map<std::string, std::string> gameAttributes_t;
15 typedef std::vector<bBoard> positions_t;
16 
17 //-----------------------------------------------------------------------
18 
19 /** game representation, singleton */
20 class bGame : public bConfigurableGame {
21 public:
22  bGame();
23  virtual ~bGame() override;
24 
25  bGame(bGame const&) = delete;
26  bGame(bGame&&) = delete;
27  bGame& operator=(bGame const&) = delete;
28  bGame& operator=(bGame&&) = delete;
29 
30  operator std::string() const;
31 
32  void newGame();
33  void setFEN(std::string const& fenstr);
34  void setFENInitialPos();
35 
36  bool playUIsuppliedMove(std::string const& coordmove);
37  bool playGameMove(bCoordMove const& coordmove);
38  bool playGameMoveSeries(std::string const& coordmoves);
39  void revertGameMove();
40 
41  std::string getResult(gameResult_t rs) const;
42  void setResult(gameResult_t rs);
43  gameResult_t getResult() const { return m_result; }
44 
46 
47  void setLevel(bLevel const& l) { m_level = l; }
48  bLevel& getLevel() { return m_level; }
49  positions_t& getPositions() { return m_positions; }
50  bool getRandom() const { return m_random; }
51  void setRandom(bool const r) { m_random = r; }
52  void setPlayerName(std::string const& n);
53 
54  void DoSearch();
55  void AbortSearch();
56  void WaitForSearchEnd();
57 
61 
62 private:
63  std::string movesinpgnformat() const;
64 
65  gameResult_t m_result = gameResult::GR_UNKNOWN; // TODO: move to last position
66  gameAttributes_t m_pgnTags;
67  gameAttributes_t m_optTags;
68  positions_t m_positions; // TODO: convert to class bPositions
69  bLevel m_level;
70  bool m_random =
71 #if defined(BELOFTE_NORANDOM) || defined(_DEBUG)
72  false;
73 #else
74  true;
75 #endif
76 };
77 
78 //-----------------------------------------------------------------------
79 
80 class bGameWithTest final : public bGame {
81 public:
82  bGameWithTest();
83  virtual ~bGameWithTest() final;
84 
85  int64_t DoPerft(depth_t const d, bSearchAlgorithm& sa);
86 
87  bEpdResult evalEpdPosition(bFen const& fen, bEpdOpCodes& opcodes,
88  epdTest_t const typeOfTest);
89  bEpdResult evalPerftResult(bFen const& fen, bEpdOpCodes& opcodes);
90 
91 private:
92  bEpdResult evalEpdPosResult(bEpdOpCodes& opcodes, bPgnMove const& m,
93  epdTest_t const typeOfTest);
94 };
95 
96 #endif // defined GAME_H
97 
98 // eof
int_fast16_t bScore
used to return id of move in movelist
Definition: belofte.h:104
int_fast8_t depth_t
Definition: belofte.h:105
board
Definition: board.h:111
allow custom methods to be attached to game
simple coordmove, with 4 characters, or 5 characters in case of promotion mostly used for interface
Definition: san.h:62
FEN string.
Definition: board.h:17
game representation, singleton
Definition: game.h:20
bool playGameMove(bCoordMove const &coordmove)
Definition: game.cpp:186
bScore EvalForPlayer(bBoard &b)
Definition: game.cpp:124
bGame & operator=(bGame &&)=delete
void revertGameMove()
required for Winboard protocol, not supported in UCI (except debug)
Definition: game.cpp:214
bool playUIsuppliedMove(std::string const &coordmove)
Definition: game.cpp:153
void setPlayerName(std::string const &n)
Definition: game.cpp:62
gameResult_t EvalFinalScore(bBoard &b)
Definition: game.cpp:134
bGame & operator=(bGame const &)=delete
bGame(bGame &&)=delete
void WaitForSearchEnd()
Called in separate thread, sure to terminate normally.
Definition: game.cpp:107
void AbortSearch()
Definition: game.cpp:99
void newGame()
Definition: game.cpp:29
void setRandom(bool const r)
Definition: game.h:51
bScore MaterialEvalForPlayer(bBoard &b)
Definition: game.cpp:129
void DoSearch()
Start search thread and exit.
Definition: game.cpp:80
bGame()
Definition: game.cpp:15
bool playGameMoveSeries(std::string const &coordmoves)
all moves in a single string
Definition: game.cpp:176
void setResult(gameResult_t rs)
Definition: game.cpp:147
void setFEN(std::string const &fenstr)
Definition: game.cpp:54
gameResult_t getResult() const
Definition: game.h:43
bGame(bGame const &)=delete
bLevel & getLevel()
Definition: game.h:48
positions_t & getPositions()
Definition: game.h:49
virtual ~bGame() override
Definition: game.cpp:25
bool getRandom() const
Definition: game.h:50
bBoard & getCurrentPosition()
Definition: game.cpp:73
void setLevel(bLevel const &l)
Definition: game.h:47
void setFENInitialPos()
Definition: game.cpp:46
bEpdResult evalPerftResult(bFen const &fen, bEpdOpCodes &opcodes)
check perft result for different depths D[1-99] # perft test - nodes
Definition: game.cpp:377
int64_t DoPerft(depth_t const d, bSearchAlgorithm &sa)
do perft search at depth
Definition: game.cpp:283
bEpdResult evalEpdPosition(bFen const &fen, bEpdOpCodes &opcodes, epdTest_t const typeOfTest)
do actual epd position test change level if any of following set acs # set search seconds dm # set di...
Definition: game.cpp:313
virtual ~bGameWithTest() final
Definition: game.cpp:277
bGameWithTest()
Definition: game.cpp:273
Definition: level.h:51
PgnMove is for user-interface only.
Definition: san.h:12
enum tEpdTestType epdTest_t
Definition: epd_testsuite.h:21
int bEpdResult
Definition: epd_testsuite.h:12
std::map< std::string, std::string > bEpdOpCodes
Definition: epd_testsuite.h:13
@ GR_UNKNOWN
Definition: eval.h:34
enum gameResult gameResult_t
Definition: eval.h:41
std::vector< bBoard > positions_t
Definition: game.h:15
std::map< std::string, std::string > gameAttributes_t
Definition: game.h:14