UndoMove affecting copies of a board
See original GitHub issueWhen using MakeMove
and UndoMove
I observed the following unusual behaviour with UndoMove
.
To explain, originalBoard
is the FEN string for the board before we do anything. Then, we make a move, and see the result in afterMove
. Then, I create a new node in the search tree - and as part of that I include the data of the board (so this node can compute its legal moves and so on). The board, as it is stored in newNode
is then displayed in boardInNewNode
. Finally, on the original board, I call UndoMove(move)
. The behaviour is then that the stored board in newNode
also has the move undone, as is displayed in afterUndo
.
I’m new to C# so maybe I’m just not understanding something, but this certainly feels like a bug! My default expectation is certainly not that the board in newNode
would be mutated alongside the original board (hence why it broke my bot). At very least, if this is the intended behaviour, it should be documented!
Issue Analytics
- State:
- Created 2 months ago
- Comments:5
Top GitHub Comments
Ah I see, so it’s a C# bug instead -_- /s
I’ll choose not to go on rant about how that’s an absolutely awful design decision and just fix my code I guess…
This info might help you understand what’s going on: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/reference-types
Board
is a class, so instances of it are reference types. The behavior you’re describing is expected in C#. To get what you want, you’d need to make an actual copy of the board rather than a reference to it.