Smothered Mate

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:4th January 2021
Description:A smothered mate is a checkmate in which the opponent's king cannot move as it is surrounded by friendly pieces.

Code

//Please feel welcome to copy this code for your own creations.
fromFen("r1bqkb1r/pp1npppp/5n2/2p5/3PN3/8/PPP1QPPP/R1B1KBNR w KQkq - 0 1");

let steps = [];
let targetMove = "";

steps.push(function() {
    info("A smothered mate is a checkmate in which the opponent's king cannot move as it is surrounded by friendly pieces.\
    <br>By definition, it can only be achieved by a knight.\
    <br>See if you can find the move that delivers mate in one.");
    targetMove = "Nd6#";
});

steps.push(function() {
    info("Correct!\
    <br>This is a well known trap in the Caro–Kann Defence.");
    complete();
});

onPieceClicked(function (squareName) {
    if(targetMove == "") {
        return false;
    }

    if (squareName == sourceOfSan(targetMove)) {
        return true;
    } else {
        highlightSquareRed(squareName);
        return false;
    }
});

onMoveAttempted(function (san) {
    if (targetMove != "" && san == targetMove) {
        nextDelayed();
        targetMove = "";
        return true;
    } else {
        return false;
    }
});

onNextClicked(function () {
    showNextButton(false);
    next();
});

function nextDelayed() {
    setTimeout(next, 400);
}

function next() {
    if (steps.length > 0) {
        //remove the first function from the array and call it
        steps.shift()();
    }
}

next();