White to avoid losing completely.

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:4th January 2021
Description:It's not looking good for white here, but they can avoid a loss if they can find a stalemate.

Code

//Please feel welcome to copy this code for your own creations.
fromFen("7k/8/5q2/8/8/7p/7P/6BK w - - 0 1");
info("It's not looking good for white here, but they can avoid a loss if they can find a stalemate.");

let steps = ["Bd4", "Qxd4"];

onPieceClicked(function(squareName) {
    unhighlightAll();
    
    if(squareName == sourceOfSan(steps[0])) {
        return true;
    } else {
        highlightSquareRed(squareName);
        return false;
    }
});

onMoveAttempted(function(san) {
    if(san == steps[0]) {
        steps.shift();
        
        if(steps.length > 0) {
          setTimeout(function() {
            performMove(steps[0]);
            steps.shift();
            
            if(steps.length == 0) {
                complete();
                info("Stalemate!");
            }
          }, 500);
        } else {
          complete();
          info(" ");
        }

        return true;
    } else {
        return false;
    }
});