I want to make the knight could move to any square (NOT follow the game rule). So I change the function: canMoveKnight in file Game.js like this:
canMoveKnight(toX, toY) {
return true;
}
The result is: the knight CANNOT move at all.
But if I change the function to:
canMoveKnight(toX, toY) {
const [x, y] = this.knightPosition
return (x !== toX || y !== toY)
}
basically, just exclude the knight position. Still return TRUE in other squares. It works.
Anyone could help to explain why return TRUE for all squares NOT working?
You can play with the source code here: https://codesandbox.io/s/github/react-dnd/react-dnd/tree/gh-pages/examples_hooks_js/00-chessboard?from-embed
Fortunately, I think someone answer the question before it closed.
I tried the answer. by adding the zIndex to Knight, it does work.
Without the zIndex, the BoardSquare catch the mouse event, and BoardSquare is NOT draggable.