Today was a short programming session. The objective was to move pieces on the board by dispatching MOVE actions.
Handle MOVE actions in the game reducer
This is the first implementation of a move. I update the position as well as the fullMoveNumber. Note that I use a function called calculateNextPosition() to find the next position based on the origin (from) and destination (to) squares.
The calculateNextPosition() function was not existing yet. So I wrote a test for it:
Thanks to the two util functions developed yesterday (positionToArrayOfPieces() and arrayOfPiecesToPosition()), making this test pass wasn’t too difficult:
And with that in place, all the tests are now passing!
Playing around in Redux devtools
According to the tests everything should be working properly. Still, it’s fun to see the pieces moving on the board! Below is a small demo recorded live.
Note: don’t try this in an actual chessgame…
Tomorrow I’ll try to implement moves via Drag & Drop using React DnD.