Skip to content

Fix bot turn desync - #19

Open
iothingcloud wants to merge 1 commit into
joojoooo:mainfrom
iothingcloud:fix-bot-turn-desync
Open

Fix bot turn desync#19
iothingcloud wants to merge 1 commit into
joojoooo:mainfrom
iothingcloud:fix-bot-turn-desync

Conversation

@iothingcloud

Copy link
Copy Markdown

ChessBot::makeBotMove() has three early-return paths (stockfish API parse failure,
attempt to move wrong-coloured piece and empty source square) that skip applyMove() entirely. Subsequently no move is made and no LEDs shown, yet silently update() calls updateGameStatus(), which advances the turn unconditionally regardless of whether a move actually happened.

If Stockfish ever returns a move that doesn't parse or doesn't match the current board (e.g. after a transient API hiccup), the turn would flip while the physical board stayed untouched, permanently desyncing the game state from the board until manually fixed via FEN edit.

makeBotMove() now returns false on every no-op path (with a short backoff so repeated failures don't hammer the API), and update() only advances the turn when a move was actually applied - the bot's turn simply retries on the next loop pass instead.

@joojoooo

Copy link
Copy Markdown
Owner

I think the fix should be: stop the game and save it as "in progress" and return to the gamemode selection. As is I think it will likely fail over and over and be stuck in an endless loop and the user needs to reboot the esp32 to regain control.

remove unrelated checkers changes

ChessBot::makeBotMove() has three early-return paths (stockfish parse failure, attempt to move wrong-coloured piece, empty source square) that skip applyMove() entirely. The returns result in no move being made and no LEDs shown. update() still subsequently calls updateGameStatus(), which advances the turn unconditionally, regardless of whether a bot move actually happened.

If Stockfish ever returns a move that doesn't parse or doesn't match the current board (e.g. after a transient API hiccup), the turn flips to the human player while the physical board stayed untouched, permanently desyncing the game state from the board until manually fixed via FEN edit.

makeBotMove() now returns false on every no-op path (with a short backoff timer so repeated failures don't hammer the API). update() only advances the turn when a move was actually applied - the bot's turn simply retries on the next loop pass instead.
@iothingcloud
iothingcloud force-pushed the fix-bot-turn-desync branch from 3b251a6 to 665fe05 Compare June 29, 2026 06:58
@iothingcloud

Copy link
Copy Markdown
Author

sorry, I missed that it was merged in my local repo. no checkers in this version.

Also, the reason this triggers quite a bit in my network is because I was at the extremity of WiFi coverage using the ESP32 and i hit about 10 instances of this bug in my games. I also get the periodic "blue LED scan" as it tried to re-connect WiFi. I haven't seen the problem since.

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

Successfully merging this pull request may close these issues.

2 participants