Find the square
Details
Author: | Mark |
Rating: | |
Difficulty: | Beginner |
Date: | 3rd February 2021 |
Description: | A simple trainer to help you rapidly identify the squares on the board from their names. |
Code
let target = "";
onSquareClicked(function (squareName) {
if (squareName == target) {
highlightSquareGreen(squareName);
setTimeout(unhighlightAll, 250);
next();
} else {
highlightSquareRed(squareName);
}
});
onPieceClicked(function (_) {
return false;
});
let flipped = false;
createButton("Flip", function () {
blackAtTop(flipped);
flipped = !flipped;
});
createButton("Randomize Board", function () {
fromFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
for (let i = 0; i < 20; i++) {
let moves = getAllPossibleMoves();
if (moves.length == 0) {
break;
}
let move = moves[Math.floor(Math.random() * moves.length)];
performMove(move);
}
});
function next() {
let file = Math.floor(Math.random() * 8);
let rank = Math.floor(Math.random() * 8) + 1;
target = "abcdefgh".substr(file, 1) + rank;
info("Find the square: <b>" + target + "</b>");
}
next();