Forks or "double attacks" are tactics that enable us to capture opponents pieces by attacking multiple pieces at the same time.
Code
fromFen("rnb1kbnr/ppp2ppp/3p4/3Np1q1/4P3/8/PPPP1PPP/R1BQKBNR w KQkq - 0 1");
let steps = [];
let targetMove = "";
steps.push(function() {
info("A fork is when you attack two pieces at the same time.\
<br>Play Nxc7+ to attack both the king and rook");
targetMove = "Nxc7+";
});
steps.push(function() {
performMove("Kd8");
nextDelayed();
});
steps.push(function() {
info("Our opponent has had to move their king out of check, leaving us free to take their rook.\
Take the rook on a8 to continue.");
targetMove = "Nxa8";
});
steps.push(function() {
info("Perfect!\
<br>The knight is the perfect piece to create forks, but other pieces can be used too.");
showNextButton(true);
});
steps.push(function() {
fromFen("rn1qkb1r/ppp1pppp/3p4/3n1b2/8/3P1N2/PPP1PPPP/RNBQKB1R w KQkq - 0 1");
info("Find the move that creates a fork in this situation");
targetMove = "e4";
});
steps.push(function() {
info("Perfect!");
showNextButton(true);
});
steps.push(function() {
fromFen("r2q1rk1/ppp3pp/2n5/1b3Q2/3pP3/2NPnP2/PPP2NPP/2R2RK1 w q - 0 1");
info("Sometimes it is possible to escape a fork.\
<br>Move the queen to put our opponent in check, creating extra time to move our rook out of harm.");
targetMove = "Qe6+";
});
steps.push(function() {
performMove("Rf7");
nextDelayed();
});
steps.push(function() {
info("Now you can move your rook out of threat.");
targetMove = "Rfe1";
});
steps.push(function() {
info("Perfect");
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();