Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion projects/lib/src/xboardengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ XboardEngine::XboardEngine(QObject* parent)
: ChessEngine(parent),
m_forceMode(false),
m_drawOnNextMove(false),
m_comPhase(InitPhase),
m_parserMode(LenientMode),
m_ftName(false),
m_ftPing(false),
m_ftSetboard(false),
Expand Down Expand Up @@ -107,6 +109,7 @@ void XboardEngine::initialize()
{
if (state() == Starting)
{
m_comPhase = InitPhase;
onProtocolStart();
emit ready();
}
Expand All @@ -118,6 +121,7 @@ void XboardEngine::startGame()
m_gotResult = false;
m_forceMode = false;
m_nextMove = Chess::Move();
m_comPhase = InitPhase;
write("new");

if (board()->variant() != "standard")
Expand Down Expand Up @@ -212,6 +216,7 @@ void XboardEngine::endGame(const Chess::Result& result)
m_gotResult = true;

stopThinking();
m_comPhase = InitPhase;
setForceMode(true);
write("result " + result.toVerboseString());

Expand Down Expand Up @@ -349,6 +354,7 @@ void XboardEngine::makeMove(const Chess::Move& move)

void XboardEngine::startThinking()
{
m_comPhase = GamePhase;
setForceMode(false);
sendTimeLeft();

Expand Down Expand Up @@ -566,7 +572,10 @@ void XboardEngine::setFeature(const QString& name, const QString& val)
m_initTimer->stop();

if (val == "1")
{
initialize();
m_parserMode = Version2Mode;
}
return;
}
else
Expand Down Expand Up @@ -719,7 +728,7 @@ void XboardEngine::parseLine(const QString& line)
setFeature(feature.first, feature.second);
}
}
else if (command.startsWith("Illegal"))
else if (m_comPhase == GamePhase && command.startsWith("Illegal"))
{
forfeit(Chess::Result::Adjudication,
tr("%1 claims illegal %2")
Expand All @@ -734,6 +743,28 @@ void XboardEngine::parseLine(const QString& line)
if (str.startsWith("result"))
finishGame();
}
if (m_parserMode == Version2Mode)
return;

// parse result commands of old CECP engines
QString win = side() == Chess::Side::White ? "1-0" : "0-1";
QString loss = side() == Chess::Side::White ? "0-1" : "1-0";

if (command == "Draw")
parseLine("1/2-1/2 " + args);
else if (command == "game")
parseLine("1/2-1/2");
else if (command == "White")
parseLine(args == "resigns" ? "0-1" : "1-0");
else if (command == "Black")
parseLine(args == "resigns" ? "1-0" : "0-1");
else if (command == "computer")
parseLine(args == "resigns" ? loss : win);
else if (command == "opponent")
parseLine(loss);
else if (command == "checkmate")
parseLine( board()->sideToMove() == Chess::Side::White ? "1-0" : "0-1");
// must return after if-block or be at the end because of recursive call
}

void XboardEngine::sendOption(const QString& name, const QVariant& value)
Expand Down
2 changes: 2 additions & 0 deletions projects/lib/src/xboardengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class LIB_EXPORT XboardEngine : public ChessEngine

bool m_forceMode;
bool m_drawOnNextMove;
enum {InitPhase, GamePhase} m_comPhase;
enum {LenientMode, Version2Mode} m_parserMode;

// Engine features
bool m_ftName;
Expand Down