Ever misclick and sell the game? Well not anymore! You can now undo moves by tapping the left arrow on the keybord and also redo those same moves if you change your mind by tapping the right arrow! I did this by adding a saveMove() function which I run after every move I make. This saves the details of the last move to the moveHistory array:
- Piece Moved
- Start Position
- End Position
- Piece Captured (Just “” if None)
- Turn Colour
- Moves so far
In my undoMove() function I remove the last move done and add it to an array called redoHistory. I then set all the details to the last entry in moveHistory. I do the same in my redoMove() function excpet I use the last entry in redoHistory instead. I’ve allowed undos after checkmate so that you can look for what went wrong and try other moves that might’ve stopped it. I also added sound! You’ll be able to see / hear all of this if the video uploads instead of just a screenshot. Next I am going to add castling (for real this time).
Comments 1
Volume warning the checkmate sound is a bit loud
Sign in to join the conversation.