Hopefully fixed multi-move bug
This commit is contained in:
13
index.js
13
index.js
@@ -16,8 +16,16 @@ async function getPythonData(path, json) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var draggable = true
|
||||||
|
|
||||||
|
function onDragStart(source, piece, position, orientation) {
|
||||||
|
if (!draggable) return false
|
||||||
|
}
|
||||||
|
|
||||||
function onDrop(source, target, piece, newPos, oldPos, orientation) {
|
function onDrop(source, target, piece, newPos, oldPos, orientation) {
|
||||||
if (source == target || moves.length === 10) return 'snapback';
|
if (source == target || moves.length === 10) return 'snapback';
|
||||||
|
if (draggable == false) return
|
||||||
|
draggable = false
|
||||||
getPythonData("https://honey-motel.bnr.la/app/move", { uci: source + target, fen: fen })
|
getPythonData("https://honey-motel.bnr.la/app/move", { uci: source + target, fen: fen })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
board.position(result.fen)
|
board.position(result.fen)
|
||||||
@@ -26,9 +34,10 @@ function onDrop(source, target, piece, newPos, oldPos, orientation) {
|
|||||||
moves.push(result.san)
|
moves.push(result.san)
|
||||||
document.getElementById("guess"+guessNum+"ply"+moves.length).innerText = result.san
|
document.getElementById("guess"+guessNum+"ply"+moves.length).innerText = result.san
|
||||||
})
|
})
|
||||||
|
draggable = true
|
||||||
}
|
}
|
||||||
|
|
||||||
let answer = ["Nf3", "f6", "e3", "d5", "Ng5", "fxg5", "Qh5+", "g6", "Qe5", "Be6"]
|
let answer = ["Nh3", "h6", "e3", "e6", "Nc3", "c6", "Nf4", "Bb4", "Nh5", "g6"]
|
||||||
|
|
||||||
function validateGuess() {
|
function validateGuess() {
|
||||||
if (moves.length != 10) return;
|
if (moves.length != 10) return;
|
||||||
@@ -68,4 +77,6 @@ const board = Chessboard('board', {
|
|||||||
pieceTheme: './pieces/{piece}.png',
|
pieceTheme: './pieces/{piece}.png',
|
||||||
draggable: true,
|
draggable: true,
|
||||||
onDrop: onDrop,
|
onDrop: onDrop,
|
||||||
|
onDragStart: onDragStart
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user