Introduction to pins

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:4th January 2021
Description:pins allow you to 'pin' a piece in place so that it can't be moved without threatening a more important piece.

Code

fromFen("r3k2r/pbp1qppp/1pn5/3p4/3P2Q1/2P4P/PPN2PP1/R1B2RK1 w Qkq - 0 1");

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

steps.push(function() {
    info("A piece is pinned if it under threat, but moving it will expose a more important piece.\
    <br>Play Re1 to pin our opponent's queen.");

    targetMove = "Re1";
});

steps.push(function() {
    info("Great!\
    <br>Our opponent cannot move their queen to safety, as it would put their king in check.");
    showNextButton(true);
});

steps.push(nextDelayed);

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

steps.push(function() {
    info("Now we are free to capture our opponent's queen");
    targetMove = "Rxe7";
});

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

steps.push(function() {
    fromFen("r1bqkbnr/ppp2ppp/2np4/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1");
    info("Opportunities for pins come up in openings that involve our opponent playing Ne6.\
    <br>Move your bishop to pin their knight.");
    targetMove = "Bb5";
});

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

steps.push(function() {
    fromFen("rn1qkbnr/ppp2p1p/3p2p1/4p3/2B1P1b1/2N2N2/PPPP1PPP/R1BQK2R w KQkq - 0 1");
    info("In the Légal Mate, our knight is pinned by the bishop on g4.\
    <br>Instead of protecting the queen, try playing Nxe5.");
    targetMove = "Nxe5";
});

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

steps.push(function() {
    info("We can get checkmate in 2 moves, see if you can find them.");
    targetMove = "Bxf7+";
});

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

steps.push(function() {
    targetMove = "Nd5#";
});

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