Skip to content

Commit

Permalink
Fixed visit lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-bovet committed May 23, 2021
1 parent 7361686 commit 560cf9b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Shared/Engine/Engine/ChessGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class ChessGame {
typedef std::function<void(MoveNode &node)> NodeCallback;
typedef std::function<void(MoveNode &node, int cursor)> 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) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
});
}
Expand Down

0 comments on commit 560cf9b

Please sign in to comment.