From 18294b0606db259e7036d0c1a2f7531f0a37c227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Thu, 7 Jan 2021 23:32:27 +0200 Subject: [PATCH] Stop a piece from capturing itself --- shatrizualizer.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shatrizualizer.html b/shatrizualizer.html index 09c461c..a15f829 100644 --- a/shatrizualizer.html +++ b/shatrizualizer.html @@ -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) {