Skip to content

Commit

Permalink
Bugfix: Move Number in starting positions is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
Isarhamster committed Nov 30, 2024
1 parent 68d21c1 commit bff0ca5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
14 changes: 6 additions & 8 deletions src/database/gamecursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ GameCursor::~GameCursor()

void GameCursor::initCursor()
{
m_nodes.append(Node());
Node n = Node();
m_nodes.append(n);
if (m_currentBoard)
{
m_currentNode = ROOT_NODE;
Expand Down Expand Up @@ -103,7 +104,7 @@ void GameCursor::clear(const QString& fen, bool chess960)
m_nodes.clear();
m_startingBoard.setChess960(chess960);
m_startingBoard.fromFen(fen);
m_startPly = (m_startingBoard.moveNumber() - 1) * 2 + (m_startingBoard.toMove() == Black);
m_startPly = (m_startingBoard.moveNumber()) * 2 - 1 + ((m_startingBoard.toMove() == Black) ? 1:0);
initCursor();
}

Expand Down Expand Up @@ -210,7 +211,7 @@ bool GameCursor::atLineEnd(MoveId moveId) const
MoveId node = makeNodeIndex(moveId);
if (node == NO_MOVE)
{
return false;
node = ROOT_NODE;
}
return m_nodes[node].nextNode == NO_MOVE;
}
Expand Down Expand Up @@ -255,11 +256,8 @@ int GameCursor::moveNumber(MoveId moveId) const
MoveId node = makeNodeIndex(moveId);
if(node != NO_MOVE)
{
if(int plyNum = plyNumber(node))
{
return (m_startPly + plyNum - 1) / 2 + 1;
}
return 0;
int plyNum = plyNumber(node);
return (m_startPly + plyNum - 1) / 2 + 1;
}
return -1;
}
Expand Down
19 changes: 13 additions & 6 deletions src/database/pgndatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,14 +825,10 @@ inline void PgnDatabase::parseMoveToken(GameX* game, QString token)
QChar c = token.at(0);
if (c.isDigit())
{
int x = game->ply()+1; // We still need to enter the next move
int n = 2*token.toInt(); // Convert move to ply
if (abs(n-x)>1)
{
m_variation = -1;
}
moveNumberFound = token.toInt();
return;
}

if (token.startsWith("..."))
{
white = false;
Expand All @@ -848,6 +844,17 @@ inline void PgnDatabase::parseMoveToken(GameX* game, QString token)

if (token.isEmpty()) return;

if (found)
{
int currentMoveNumber = game->cursor().moveNumber();
if (m_newVariation && !white) currentMoveNumber--;
if (currentMoveNumber != moveNumberFound)
{
m_variation = -1;
return;
}
}

if(m_newVariation)
{
bool dummyNeeded = found && (((white && game->board().whiteToMove()) ||
Expand Down
1 change: 1 addition & 0 deletions src/database/pgndatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class PgnDatabase : public Database
int percentDone;
bool white;
bool found;
int moveNumberFound;
bool bUse64bit {false};
};

Expand Down

0 comments on commit bff0ca5

Please sign in to comment.