async function getPythonData(path, json) {
try {
const response = await fetch(path, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(json)
});
// This waits for the JSON to be unpacked
const data = await response.json();
// Now you can return the actual data object
return data;
} catch (error) {
console.error("Failed to get data:", error);
}
}
function onDrop(source, target, piece, newPos, oldPos, orientation) {
if (source == target || moves.length === 10) return 'snapback';
getPythonData("https://honey-motel.bnr.la/app/move", { uci: source + target, fen: fen })
.then(result => {
board.position(result.fen)
fen = result.fen
if (result.san == undefined) return
moves.push(result.san)
document.getElementById("guess"+guessNum+"ply"+moves.length).innerText = result.san
})
}
let answer = ["Nf3", "f6", "e3", "d5", "Ng5", "fxg5", "Qh5+", "g6", "Qe5", "Be6"]
function validateGuess() {
if (moves.length != 10) return;
for (let i = 0; i < 10; i++) {
if (answer.includes(moves[i])) {
document.getElementById("guess"+guessNum+"ply"+(i+1)).style.backgroundColor = "orange"
}
if (moves[i] === answer[i]) {
document.getElementById("guess"+guessNum+"ply"+(i+1)).style.backgroundColor = "green"
}
}
document.getElementById("guessDisplay").innerHTML += "
"
guessNum++
for (let i = 0; i < 10; i++) {
document.getElementById("guessDisplay").innerHTML += `