Back-rank mate

Details

Author:mark
Rating:
Difficulty:Beginner
Date:15th December 2020
Description:Back-rank mate is a common situation that can be used to create checkmate in beginner level games.

Code

var targetSquare = "";

function resetOnPieceClicked() {
    onPieceClicked(function (squareName) {
        if (squareName == targetSquare) {
            return true;
        } else {
            highlightSquareRed(squareName);
            return false;
        }
    });
}
resetOnPieceClicked();


var steps = [];

steps.push(function () {
    fromFen("k7/ppp5/8/8/8/8/PPP5/1K1R4 w - - 0 1");

    info("Back-rank mate is caused when a rook or queen is moved to the back rank causing checkmate\
   <br><br>\
   Find the move that creates checkmate to continue.");

    targetSquare = "d1";
    onMoveAttempted(function (san) {
        if (san == "Rd8#") {
            nextDelayed();
            return true;
        } else {
            return false;
        }
    });
});

steps.push(function() {
    info("Correct.");
    showNextButton(true);
});

steps.push(function() {
    fromFen("k6r/ppp4p/6p1/8/8/8/PPPQ4/1K1R4 w - - 0 1");

    info("It can be guarded against by keeping a rook on the back rank.\
    <br><br>\
    We can counter this by using two pieces to attack the back rank:\
    <ul>\
    <li>The first removes the rook</li>\
    <li>The second attacks the king</li>\
    </ul>\
    Find the moves that create checkmate to continue.");

    targetSquare = "d2";
    onMoveAttempted(function (san) {
        if (san == "Qd8+") {
            nextDelayed();
            return true;
        } else {
            return false;
        }
    });
});

steps.push(function() {
    performMove("Rxd8");

    targetSquare = "d1";
    onMoveAttempted(function (san) {
        if (san == "Rxd8#") {
            nextDelayed();
            return true;
        } else {
            return false;
        }
    });
});

steps.push(function() {
    info("Correct.");
    showNextButton(true);
});

let flightSquare = "";

steps.push(function() {
    fromFen("k2r4/pp4Qp/6p1/2p5/8/8/PPP5/1K6 w - - 0 1");
    info("Another way of protecting against back-rank mate is by creating a flight square for the king\
    <br><br>Move one of the pawns to continue.");

    onPieceClicked(function (squareName) {
        switch(squareName) {
            case "a2":
            case "b2":
            case "c2":
                return true;
            default:
                highlightSquareRed(squareName);
                return false;
        }
    });

    onMoveAttempted(function (san) {
        switch(sourceOfSan(san)) {
            case "a2":
            case "b2":
            case "c2":
                resetOnPieceClicked();
                nextDelayed();
                flightSquare = sourceOfSan(san);
                return true;
            default:
                return false;
        }
    });
});

steps.push(function() {
    performMove("Rd1+");
    nextDelayed();
});

steps.push(function() {
    info("Now you can move your king to the newly created space");
    targetSquare = "b1";

    onMoveAttempted(function (san) {
        if (sourceOfSan(san) == "b1" && destOfSan(san) == flightSquare) {
            nextDelayed();
            return true;
        } else {
            return false;
        }
    });
});

steps.push(function() {
    info("Correct.");
    showNextButton(true);
});

steps.push(function() {
    fromFen("k4r2/ppp3pp/8/2Q2q2/8/8/PP6/K3R3 w - - 0 1");
    info("Sometimes just the threat of back-rank mate is enough to pin the opponents piece in place.\
    <br><br>\
    Black believes that the rook is protecting the queen, but we are free to capture it.\
    <br>Capture the black queen to continue.");

    targetSquare = "c5";
    onMoveAttempted(function (san) {
        if (san == "Qxf5") {
            nextDelayed();
            return true;
        } else {
            return false;
        }
    });
});

steps.push(function() {
    performMove("Rb8");
    nextDelayed();
});

steps.push(function() {
    info("Black couldn't take our queen, as it would have made him vulnerable to a back-rank mate.");
    showNextButton(true);
});

steps.push(function() {
    info("This finishes our lesson on back-rank mate.");
    complete();
});

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

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

function next() {
    if (steps.length > 0) {
        steps.shift()();
    }
}

next();