From 5d8e8da87f9b6d66483d5f20bf4f4dee7da94fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 10 Jan 2021 18:36:52 +0200 Subject: [PATCH] Add options for start squares of kings --- takhta.html | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/takhta.html b/takhta.html index 47d2f39..743da2a 100644 --- a/takhta.html +++ b/takhta.html @@ -34,6 +34,18 @@ #board tbody :nth-child(n) :first-child { background-color: unset; } + #options { + display: table; + } + .option { + display: table-row; + } + .option :nth-child(1) { + display: table-cell; + } + .optionvalues :nth-child(1) { + display: inline; + } body { display: flex; flex-wrap: wrap; @@ -189,6 +201,36 @@

+

+

+
+
White king on
+
+ + +
+
+
+
Black king on
+
+ + +
+
+
+

Moves thus far

@@ -201,6 +243,9 @@ let form = document.getElementById('input'); form.onsubmit = moveEvent; + document.getElementById('whited1').checked = true; + document.getElementById('blackd8').checked = true; + let moveHistory = []; let moveFuture = []; @@ -432,10 +477,15 @@ let ret = doMove(move); if ('error' in ret) { alert(ret.error); + // Put back in list of undone moves + moveFuture.push(move); + return false; } // Mark it as un-undone in the list of moves document.getElementById('movelist').children[index].className = ''; + + return true; } function flipBoard() { @@ -532,6 +582,32 @@ link.click(); actions.removeChild(link); } + + function setupKings() { + let options = new FormData(document.getElementById('options')); + let whiteKing = options.get('whiteking'); + let whiteQueen = whiteKing === 'd1' ? 'e1' : 'd1'; + let blackKing = options.get('blackking'); + let blackQueen = blackKing === 'd8' ? 'e8' : 'd8'; + + // Undo all moves + while (moveHistory.length > 0) { + undoMove(); + } + + // Place the kings and queens + document.getElementById(whiteKing).firstChild.data = '♔'; + document.getElementById(whiteQueen).firstChild.data = '♕'; + document.getElementById(blackKing).firstChild.data = '♚'; + document.getElementById(blackQueen).firstChild.data = '♛'; + + // Redo all the moves we can + while (moveFuture.length > 0) { + if (!redoMove()) { + break; + } + } + }