From 560cf9bf09798608b19a1c1b0bacc1347736cb80 Mon Sep 17 00:00:00 2001 From: Jean Bovet Date: Sun, 23 May 2021 11:07:33 -0700 Subject: [PATCH] Fixed visit lookup --- Shared/Engine/Engine/ChessGame.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Shared/Engine/Engine/ChessGame.hpp b/Shared/Engine/Engine/ChessGame.hpp index 2992991..fae67ae 100644 --- a/Shared/Engine/Engine/ChessGame.hpp +++ b/Shared/Engine/Engine/ChessGame.hpp @@ -82,8 +82,7 @@ class ChessGame { typedef std::function NodeCallback; typedef std::function NodeCallback2; - // Find the node that represents the move at `atIndex`. Note that `atIndex==0` represents - // the "root" node, which is not a move. The first move is actually at `atIndex==1`. + // Find the node that represents the move at `atIndex`. // cursor: the cursor used to keep track of the current index while recursively looking up void lookupNode(int cursor, int atIndex, MoveIndexes indexes, NodeCallback callback) { if (cursor == atIndex) { @@ -99,9 +98,9 @@ class ChessGame { if (cursor < untilCursorIndex) { int varIndex = indexes.moves[cursor]; assert(varIndex < variations.size()); - // TODO: revisit the cursor+1 which is needed because the root node is at cursor==0 - callback(variations[varIndex], cursor+1); - variations[varIndex].visit(cursor+1, indexes, untilCursorIndex, callback); + auto & node = variations[varIndex]; + callback(node, cursor); + node.visit(cursor+1, indexes, untilCursorIndex, callback); } } @@ -180,7 +179,9 @@ class ChessGame { void setCurrentMoveUUID(unsigned int uuid) { root.visit(0, moveIndexes, (int)moveIndexes.moves.size(), [this, &uuid](auto & node, auto cursor) { if (node.uuid == uuid) { - moveIndexes.moveCursor = cursor; + // Add one to the current cursor because cursor==0 represents the root node + // which is not a move. The first real move starts at cursor==1. + moveIndexes.moveCursor = cursor + 1; } }); }