Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndoMove does not place pieces back #135

Open
megamaz opened this issue Jul 22, 2023 · 3 comments
Open

UndoMove does not place pieces back #135

megamaz opened this issue Jul 22, 2023 · 3 comments

Comments

@megamaz
Copy link

megamaz commented Jul 22, 2023

Been doing some testing and noticed after a while that the bot was failing to see checkmate, despite having a clear if statement checking for it. After a bit I decied to output the FEN strings, and found this...

before any moves are made: rnbqkbnr/pppp1ppp/4p3/6N1/8/8/PPPPPPPP/RNBQKB1R b KQkq - 1 2
after making Move: 'e8e7' rnbq1bnr/ppppkppp/4p3/6N1/8/8/PPPPPPPP/RNBQKB1R w KQ - 2 3
after undoing Move: 'e8e7' rnbqkbnr/pppp1ppp/4p3/6N1/8/8/PPPPPPPP/RNBQKB1R b KQ - 3 3
after making Move: 'd8g5' rnb1kbnr/pppp1ppp/4p3/6q1/8/8/PPPPPPPP/RNBQKB1R w KQ - 4 4
after undoing Move: 'd8g5' rnbqkbnr/pppp1ppp/4p3/8/8/8/PPPPPPPP/RNBQKB1R b KQ - 5 4
after making Move: 'd8f6' rnb1kbnr/pppp1ppp/4pq2/8/8/8/PPPPPPPP/RNBQKB1R w KQ - 6 5
after undoing Move: 'd8f6' rnbqkbnr/pppp1ppp/4p3/8/8/8/PPPPPPPP/RNBQKB1R b KQ - 7 5

There is a white Knight on g5 that can be seen in the original FEN. When it is not taken, e8e7, the UndoMove function works fine. After it is taken, d8g5, the UndoMove function fails to place the Knight back, as the FEN string shows.

After some more testing, I found the culprit to be the board.TrySkipTurn() method. If placed twice in a row, effectively doing nothing, the UndoMove function fails to place a piece back,

@QuinnCG
Copy link

QuinnCG commented Jul 22, 2023

If placed twice in a row, effectively doing nothing, the UndoMove function fails to place a piece back

If starting on white, wouldn't it simply skip whites turn then skip blacks turn?

I'm having, I think, similar issues as you. The AddPieceAtSquare method is throwing "Index was out of bounds of the array." exception when I call UndoMove after calling TrySkipTurn twice in a row. I'm calling
MakeMove -> TrySkipTurn -> MakeMove -> TrySkipTurn -> UndoSkipTurn -> UndoMove -> UndoSkipTurn -> UndoMove.

I'm not 100% sure if this is intended behavior and I'm just missing it or not.

@megamaz
Copy link
Author

megamaz commented Jul 22, 2023

For now my solution is

Board newboard = Board.CreateBoardFromFEN(board.GetFenString());
newboard.TrySkipTurn();

though I'm not sure how compliant that is with the rules.

@dudecon
Copy link

dudecon commented Jul 23, 2023

For now my solution is

Board newboard = Board.CreateBoardFromFEN(board.GetFenString());
newboard.TrySkipTurn();

though I'm not sure how compliant that is with the rules.

Complies fine with the rules IMO, but will be slow, so it's not an ideal fix. Hopefully we'll get a real solution soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants