Stop a piece from capturing itself

This commit is contained in:
Juhani Krekelä 2021-01-07 23:32:27 +02:00
parent 015196a52d
commit 18294b0606
1 changed files with 6 additions and 0 deletions

View File

@ -306,6 +306,12 @@
renderedPromotion = whiteMove ? whitePieces[promotion] : blackPieces[promotion];
}
// Are we moving the piece onto itself?
if (startLetter === endLetter && startNumber === endNumber) {
alert('Start and end squares of the move cannot be identical');
return;
}
// Are we moving the piece from where it is located?
let startSquare = document.getElementById(startLetter + startNumber);
if (startSquare.childNodes.length === 0) {