question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UndoMove affecting copies of a board

See original GitHub issue

When using MakeMove and UndoMove I observed the following unusual behaviour with UndoMove.

image

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:closed
  • Created 2 months ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
Eldriitchcommented, Jul 24, 2023

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.

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…

2reactions
raphaelcastanedacommented, Jul 23, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unmake move vs copy board in chess programming [closed]
As you say, copying the whole board is likely to slow things down quite a bit. I suggest making an undo list, to...
Read more >
Move published components
Move published components and component sets between files, without breaking links to instances. Use this process to split up large libraries into smaller ......
Read more >
Undo, redo, or repeat an action
You can undo, redo, or repeat many actions Microsoft Lists, SharePoint, and Teams. You can undo changes, even after you have saved, and...
Read more >
Undo "Move to Repository" on Dialog
So It would either need some warnings that it is a non-reversible operation, or we should have the option to copy the dialog...
Read more >
Solved: How do I copy an existing board and set it up so i...
I have copied an existing board for a new project and changed the filter so that it reflects the new project. However, this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found