Checkmating with two rooks

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:28th December 2020
Description:In this lesson we learn how to checkmate using two rooks to push the king to the edge of the board.

Code

fromFen("8/8/8/4k3/R7/8/8/K6R w - - 0 1");
let targetMove = "";

var steps = [];
steps.push(function() {
   info("In this lesson we will learn how to checkmate using two rooks.");
   showNextButton(true);
});

steps.push(function() {
   info("The basic idea is to drive the opponents king to the edge of the board\
   <br>Play Rh5+ to continue.");
   targetMove = "Rh5+";
});

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

steps.push(function() {
   info("Correct!\
   <br>Keep pushing the king to the edge of the board");
   targetMove = "Ra6+";
});

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

steps.push(function() {
   targetMove = "Rh7+";
});

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

steps.push(function() {
   info("The king is now at the edge of the board and can be checkmated!");
   targetMove = "Ra8#";
});

steps.push(function() {
   info("Checkmate!");
   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();