11#pragma GCC diagnostic push
12#pragma GCC diagnostic ignored "-Weffc++"
21#pragma GCC diagnostic pop
33 m_pgnTags[
"Site"] =
"";
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;
77 if (
App().m_reader.isBatchMode()) {
84 if (!player.empty()) m_pgnTags[
"White"] = player;
86 if (!opponent.empty()) m_pgnTags[
"Black"] = opponent;
89 if (!player.empty()) m_pgnTags[
"Black"] = player;
91 if (!opponent.empty()) m_pgnTags[
"White"] = opponent;
122 }
catch (...) {
throw;
143 m_level.setDepthCommand(d);
145 std::string sAlgName =
getAlgorithm()->operator std::string();
146 std::string sEval =
getEval()->operator std::string();
148 if (sAlgName ==
"Perft")
setEval(
"None");
162 }
catch (...) {
throw;
168 if (sAlgName ==
"Perft")
setEval(sEval);
190 m_pgnTags[
"Result"] =
getResult(m_result);
201 return std::all_of(vstrings.begin(), vstrings.end(),
202 [
this](std::string
const& s)
203 { return this->playGameMove(bCoordMove(s)) || this->playPGNMoves(s); });
210bool bGame::playGameMove(
bCoordMove const& coordmove)
221 if (cm == coordmove) {
223 newboard.applyMove(m);
224 newboard.setMove(m.getFromTo());
225 newboard.calcGameStage();
226 m_positions.push_back(newboard);
250 auto filterMoveNum = [](
const std::string& str) -> std::string {
252 size_t n = str.find_first_not_of(
"0123456789. */-\r\n\t");
253 return (n == std::string::npos) ?
"" : str.substr(n);
256 bool hasPlayedMove =
false;
258 std::regex commentsPatern(
"\\{[^}]*\\}");
259 std::string sMoveList = std::regex_replace(sPGNMoveList, commentsPatern,
"");
260 std::regex alternativesPatern(
"\\([^)]*\\)");
261 sMoveList = std::regex_replace(sPGNMoveList, alternativesPatern,
"");
263 if (sMoves.size() > 0) {
264 for (
auto it = sMoves.begin(); it != sMoves.end(); ++it) {
268 std::string sMove = filterMoveNum(*it);
274 if (playGameMove(cm)) hasPlayedMove =
true;
280 return hasPlayedMove;
288 if (m_positions.size() > 1) {
289 m_positions.pop_back();
316 }
catch (...) {
throw;
324std::string bGame::movesinpgnformat()
const
326 std::stringstream sMoves;
327 std::stringstream sMovePrefix;
329 if (m_positions.size() > 1) {
330 if (m_positions[0].blackToMove()) {
331 sMovePrefix << m_positions[0].getMoveNumber() <<
"... ";
334 for (
unsigned int i = 1; i < m_positions.size(); ++i) {
335 bBoard newboard(m_positions[i]);
336 bBoard ob(m_positions[i - 1]);
337 if (newboard.getMove()) {
338 if (ob.whiteToMove()) {
339 sMovePrefix << newboard.getMoveNumber() <<
". ";
341 bPgnMove pm(ob, newboard.getMove());
342 sMoves << sMovePrefix.str() << pm <<
" ";
353bGame::operator std::string()
const
355 std::string sGameHeader;
358 for (
auto const& x : m_pgnTags) {
360 sGameHeader +=
"[" + x.first +
" \"" + x.second +
"\"]" +
"\n";
365 for (
auto const& x : m_optTags) {
366 if (x.second.size()) {
367 sGameHeader +=
"[" + x.first +
" \"" + x.second +
"\"]" +
"\n";
370 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)
constexpr bool whiteToMove() const
constexpr bScore minimizing() const
constexpr bmove_t getBMoveT() const
void setEval(std::string const &e)
bSearchAlgorithm * getAlgorithm() const
bPositionEvaluation * getEval() const
simple coordmove, with 4 characters, or 5 characters in case of promotion mostly used for interface
bMove getEpdMoveInPosition(bFen const &fen)
do actual epd position test
void setResult(gameResult_t gr)
void setPlayerName(std::string const &n)
constexpr bool isStandardPgn() const
int64_t DoPerft(bSearchAlgorithm &sa, depth_t const d)
do perft search at depth in case of Perft algorithm, temporarily set evaltype to None
void WaitForSearchEnd()
Called in separate thread, sure to terminate normally.
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...
void revertGameMove(std::string const &reason)
required for Winboard protocol, not supported in UCI (except debug)
void DoSearch()
Start search thread and exit in case of batch mode, will wait until end of search.
bool playGameMoveSeries(std::string const &coordmoves)
all moves in a single string
void setFEN(std::string const &fenstr)
int64_t DoPerftCommand(depth_t const d)
do perft search using SearchPerft algorithm at depth
gameResult_t getResult() const
bScore EvalForPlayer(bBoard const &b, gameResult_t gr)
bBoard & getCurrentPosition()
movenum_t generateMoves(bBasicBoard const &b)
generate moves if not yet generated
constexpr movenum_t getBestMoveId() const
constexpr movenum_t getNumberOfMoves() const
PgnMove is for user-interface only.
static bool isDrawResult(gameResult_t const gr)
virtual bScore getEvaluation(bBoard const &b, gameResult_t gr) const
get final score (+-SCORE_MATE, SCORE_THEORETIC_DRAW) or 0
constexpr int64_t getNodes() const
void SearchBestMove(bBoard &b, bMoveList &ml)
Generic search, will call (non-)recursive method per algorithm only when there are moves to be played...
static constexpr bool isDrawScore(bScore const score)
constexpr bool isUndefinedScore() const
virtual void sendResult(bBoard const &b, gameResult_t const gr) 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)
constexpr bScore SCORE_MATE
enum gameResult gameResult_t
stringList const stringSplit(std::string src, std::string const &delim)
Split delimited long string into a vector.
std::vector< std::string > stringList
std::string currentDate()