Scholar's mate

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:27th December 2020
Description:Scholars mate allows you to checkmate your opponent in 4 moves. It is great against beginners but it is also easy to defend against.

Code

let targetMove = "";

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;
    }
});

var steps = [];

steps.push(function() {
   info("Scholar's mate allows you to checkmate your opponent in 4 moves.\
   <br>It is great against beginners but it is also easy to defend against."); 
   
   showNextButton(true);
});

steps.push(function() {
   highlightSquareYellow("f7");
   info("It relies on the weekness of the f7 square, we aim to get our queen to occupy it.");
   showNextButton(true);
});

steps.push(function() {
    unhighlightAll();
    info("Start by playing e4, this defends the center as normal, and allows us to move our queen and bishop");
    targetMove = "e4";
});

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

steps.push(function() {
    info("Next we move our bishop to c4, attacking f7");
    targetMove = "Bc4";
});

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

steps.push(function() {
    info("Next we move our queen to h5, hopefully our opponent will play Nf6 to attack it.");
    targetMove = "Qh5";
});

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

steps.push(function() {
    info("Finally we play Qxf7# to checkmate");
    targetMove = "Qxf7#";
});

steps.push(function() {
    info("Checkmate!");
    complete();
});

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();