Mate In One

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:6th December 2020
Description:It's white's turn and they can achieve checkmate in a single move.

Code

//Please feel welcome to copy this code for your own creations.
fromFen("k7/ppp5/8/8/8/8/PPP5/1K1R4 w - - 0 1");
info("It's white's turn, and they can win in one move.<br>Can you find it?");

onPieceClicked(function(squareName) {
    unhighlightAll();

    if(squareName == "d1") {
        selectPiece(squareName);
        info("This is the correct piece to move, where should you move it to?");

        let moves = getPossibleMoves(squareName);
        for(let move of moves) {
            highlightSquareYellow(move);
        }
    } else {
        highlightSquareRed(squareName);
        info("This is not the correct piece to move.");
        return false;
    }
});

onMoveAttempted(function(san) {
    if(san == "Rd8#") {
        performMove(san);
        info("Correct!");
        complete();
    } else {
        info("Incorrect, try again");
        return false;
    }
});