11#pragma GCC diagnostic push
12#pragma GCC diagnostic ignored "-Weffc++"
21#pragma GCC diagnostic pop
33 m_pgnTags[
"Site"] =
"";
34 m_pgnTags[
"Date"] = belofte::currentDate();
35 m_pgnTags[
"Round"] =
"";
38 m_pgnTags[
"Result"] =
getResult(m_result);
40 m_optTags[
"eloWhite"] =
"";
41 m_optTags[
"eloBlack"] =
"";
49 m_positions.emplace_back(
bFen(
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"));
50 m_optTags.erase(
"SetUp");
51 m_optTags.erase(
"FEN");
57 m_positions.emplace_back(
bFen(fenstr));
58 m_optTags[
"SetUp"] =
"1";
59 m_optTags[
"FEN"] = fenstr;
65 m_pgnTags[
"White"] = n;
67 m_pgnTags[
"Black"] = n;
75 return m_positions.back();
83 if (
App().m_reader.isBatchMode()) {
120 }
catch (...) {
throw;
128 bLevel oldLevel = m_level;
141 }
catch (...) {
throw;
172 if (m_expecting ==
"" || m_expecting == s) {
194 m_pgnTags[
"Result"] =
getResult(m_result);
202 std::vector<std::string> vstrings = belofte::stringSplit(coordmoves,
" ");
204 return std::all_of(vstrings.begin(), vstrings.end(),
205 [
this](std::string
const& s){ return this->playGameMove(bCoordMove(s)); });
213 for (
movenum_t moveid = 1; moveid <= n_moves; moveid++) {
216 if (cm == coordmove) {
217 m_positions.emplace_back(b,
const_cast<bMove&
> (m));
239 m_positions.pop_back();
259 bPgnMove pgnmove(currentPosition, m);
260 iReturn = evalEpdResult(opcodes, pgnmove);
263 }
catch (...) {
throw;
280 if (opcodes.find(
"bm") != opcodes.end()) {
281 belofte::stringList
const sMoves = belofte::stringSplit(opcodes[
"bm"],
" ");
282 if (std::any_of(sMoves.begin(), sMoves.end(),
283 [m](std::string
const& sm)
284 { return m == sm; })) {
287 }
else if (opcodes.find(
"am") != opcodes.end()) {
289 belofte::stringList
const sMoves = belofte::stringSplit(opcodes[
"am"],
" ");
290 if (std::none_of(sMoves.begin(), sMoves.end(),
291 [m](std::string
const& sm)
292 { return m == sm; })) {
297 App().
bout <<
"found : " << m <<
" - ";
313 std::string sOp =
"D" + belofte::to_string(i);
314 if (opcodes.find(sOp) != opcodes.end()) {
315 std::string sPerftResult = belofte::alltrim(opcodes[sOp]);
317 int64_t nodes =
DoPerft(search, i);
318 if (sPerftResult != belofte::to_string(nodes)) {
319 App().
bout <<
"found nodes : " << belofte::to_string(nodes) <<
" - ";
330std::string bGame::movesinpgnformat()
const
332 std::stringstream sMoves;
333 std::stringstream sMovePrefix;
335 if (m_positions.size() > 1) {
336 if (!m_positions[0].whiteToMove()) {
337 sMovePrefix << m_positions[0].getMoveNumber() <<
"... ";
340 for (
unsigned int i = 1; i < m_positions.size(); i++) {
341 if (m_positions[i].getMovePlayed()) {
342 if (m_positions[i - 1].whiteToMove()) {
343 sMovePrefix << m_positions[i].getMoveNumber() <<
". ";
347 bBoard b(m_positions[i - 1]);
348 bPgnMove pm(b, m_positions[i].getMovePlayed());
349 sMoves << sMovePrefix.str() << pm <<
" ";
359bGame::operator std::string()
const
361 std::string sGameHeader =
"";
364 for (
auto const& x : m_pgnTags) {
365 sGameHeader +=
"[" + x.first +
" \"" + x.second +
"\"]" +
"\n";
369 for (
auto const& x : m_optTags) {
370 if (x.second.size()) {
371 sGameHeader +=
"[" + x.first +
" \"" + x.second +
"\"]" +
"\n";
374 return sGameHeader +
"\n" + movesinpgnformat();
engineInterface * AppEI()
This is the main include file, needs to be included before any other include.
outputWriter sout
normal output
int64_t getConfig(std::string const &s, int64_t v)
bMove const & getMove(movenum_t const moveid) const
bMoveList & getMoveListRef()
return reference to movelist
bScore minimizing() const
bSearchAlgorithm * getAlgorithm() const
bPositionEvaluation * getEval() const
simple coordmove, with 4 characters, or 5 characters in case of promotion mostly used for interface
std::string const & getExpecting() const
bScore EvalForPlayer(bBoard const &b)
bool playGameMove(bCoordMove const &coordmove)
void revertGameMove()
required for Winboard protocol, not supported in UCI (except debug)
void setPlayerName(std::string const &n)
bEpdResult evalPerftResult(bFen const &fen, bEpdOpCodes &opcodes)
check perft result for different depths D[1-99] # perft test - nodes
void WaitForSearchEnd()
Called in separate thread, sure to terminate normally.
void setExpecting(std::string const &s)
Following command should return value as expected.
void DoSearch()
Start search thread and exit in case of batch mode, will wait until end of search.
gameResult_t EvalFinalScore(bBoard const &b)
bool playGameMoveSeries(std::string const &coordmoves)
all moves in a single string
void setResult(gameResult_t rs)
void setFEN(std::string const &fenstr)
gameResult_t getResult() const
bEpdResult evalEpdPosition(bFen const &fen, bEpdOpCodes &opcodes)
do actual epd position test
int64_t DoPerft(bSearchAlgorithm &sa, int const d)
do perft search at depth
bBoard & getCurrentPosition()
bool isExpecting(std::string const &s) const
void setDepthCommand(depth_t const d)
movenum_t getNumberOfMoves() const
PgnMove is for user-interface only.
virtual bScore getEvaluation(bBoard const &b) const =0
gameResult_t isGameEnded(bBoard const &b) const
See if board is in finite state, meaning game is ended.
bBestMoveInfo SearchBestMove(bBoard &b)
Generic search, will call (non-)recursive method per algorithm only when there are moves to be played...
virtual void sendResult(bBoard const &b, gameResult_t rs) const
virtual void sendMove(bBoard &b, bMove const &m)
virtual void sendError(std::string const &error, std::string const &description)
void setLevel(int const l)
#define EPD_PERFTMAXDEPTH
std::map< std::string, std::string > bEpdOpCodes
constexpr bScore SCORE_MATE
enum gameResult gameResult_t
constexpr bScore SCORE_PUNDEFINED
constexpr bScore SCORE_CONVERGE_BYDEPTH
constexpr bScore SCORE_POSITIVE
constexpr bScore SCORE_THEORETIC_DRAW