Complete guide to the Petrov Defence for white

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:10th January 2021
Description:The Petrov Defence starts with Black mirroring white for the first two moves. After that different variations can see either white or black ahead, although most of the time they are equal.

Code

let data = [
    {
        info: "The Petrov defence starts with us playing e4.",
        targetMove: "e4"
    },
    {
        reply: "e5"
    },
    {
        info: "Our opponent mirrors us with e5. <br>Play Nf3 as your second move.",
        targetMove: "Nf3"
    },
    {
        reply: "Nf6",
    },
    {
        info: "Our opponent mirrors us again. <br>This setup represents the Petrov Defense.",
        showNextButton: true
    },
    [
        {
            info: "In the classical variation, white's next move is Nxe5",
            targetMove: "Nxe5"
        },
        [
            {
                reply: "Nxe4"
            },
            {
                info: "Black has fallen into the trap of mirroring us here.<br>Play Qe2 to put pressure on their knight.",
                targetMove: "Qe2"
            },
        [
            {
                reply: "Nf6"
            },
            {
                info: "Black has decided to retreat to safety <br>But failed to see what happens when we play Nc6+",
                targetMove: "Nc6+"
            },
            {
                reply: "Qe7"
            },
            {
                info: "Now we can capture the queen!",
                targetMove: "Nxe7"
            },
            {
                info: "Awesome! we have captured our opponent's queen.",
                showNextButton: true
            }
        ],
        [
            {
                info: "But what if they played d5 instead of moving their knight to safety?",
                showNextButton: true
            },
            {
                reply: "d5",
                info: "Black has used his d pawn to protect his knight, play d3 to put extra pressure on it.",
                targetMove: "d3"
            },
            {
                reply: "Qe7"
            },
            {
                info: "Black has realized that the knight is lost, he can't move it to safety, so instead he goes after our knight. <br>Play dxe4 to continue.",
                targetMove: "dxe4"
            },
            {
                reply: "Qxe5"
            },
            {
                info: "We lost our knight too, but are free to take their pawn.",
                targetMove: "exd5"
            },
            {
                info: "Black cannot take our pawn because his queen is pinned, we finish up ahead by one pawn",
                showNextButton: true
            }
        ],
        [
            {
                info: "Black's best option from here is to play Qe7",
                showNextButton: true
            },
            {
                reply: "Qe7",
                info: "Our best move is to take the knight",
                targetMove: "Qxe4"
            },
            {
                info: "Black cannot take our knight here without losing their queen",
                showNextButton: true
            },
            {
                reply: "d6",
                info: "Our best reply is to play d4, backing up our knight",
                targetMove: "d4"
            },
            {
                reply: "dxe5",
                info: "Respond with dxe5",
                targetMove: "dxe5"
            },
            {
                reply: "Nc6",
                info: "from this point, you can play Nc3",
                targetMove: "Nc3"
            },
            {
                reply: "Qxe5"
            },
            {
                info: "Now we trade queens",
                targetMove: "Qxe5+"
            },
            {
                reply: "Nxe5",
            },
            {
                info: "we have a clear advantage (according to Lasha Janjgava)",
                showNextButton: true
            }
        ]
        ],
        [
            {
                info: "But what if they played Qe7 instead of taking the pawn on the third move?",
                showNextButton: true
            },
            {
                reply: "Qe7",
                info: "Our knight is under threat, protect it with the d pawn",
                targetMove: "d4"
            },
        [
            {
                reply: "d6"
            },
            {
                info: "Move the knight back to the safety of f3",
                targetMove: "Nf3"
            },
            {
                reply: "Qxe4+"
            },
            {
                info: "And play Be2 to protect our king",
                targetMove: "Be2"
            },
            {
                info: "White is ahead here, as the black queen is vulnerable to us playing Ng5",
                showNextButton: true
            }
        ],
        [
            {
                info: "But what if black played Nc6 instead of d4?",
                showNextButton: true
            },
            {
                reply: "Nc6"
            },
            {
                info: "We must play Nc3 to protect e4 after they play Qxe5",
                targetMove: "Nc3"
            },
            {
                reply: "Nxe5"
            },
            {
                info: "Reply with dxe5",
                targetMove: "dxe5"
            },
            {
                reply: "Qxe5",
            },
            {
                info: "We are free to attack the queen with f4",
                targetMove: "f4"
            },
            {
                reply: "Qe6",
                info: "And we are ahead here too.",
                showNextButton: true
            }
        ]
        ],
        [
            {
                info: "We have seen Nxe4 and Qe7 will leave black in a bad place. The best move for black is d6.",
                showNextButton: true
            },
            {
                reply: "d6"
            },
            [
                {
                    targetMove: "Nf3",
                    info: "Nf3 is the main line, it moves the knight back to safety, but allows black to play Nxe4"
                },
                {
                    reply: "Nxe4"
                },
                [
                    {
                        info: "We play d4, to control the center",
                        targetMove: "d4"
                    },
                    {
                        reply: "d5"
                    },
                    {
                        info: "Black has supported their knight on e4.",
                        showNextButton: true
                    },
                    {
                        targetMove: "Bd3",
                        info: "We can try and drive black's knight from e4 by playing Bd3. "
                    },
                    {
                        info: "This is the main line.",
                        showNextButton: true
                    }
                ],
                [
                    {
                        targetMove: "Bd3",
                        info: "Instead of playing 5.d4 d5, 6.Bd3, we can move our bishop to d3 first."
                    },
                    {
                        info: "It allows us to castle earlier forces the black knight to retreat. This is called the 'Millennium Attack'",
                        showNextButton: true
                    }
                ],
                [
                    {
                        info: "Another option is Qe2, proposed by Emanuel Lasker.",
                        targetMove: "Qe2"
                    },
                    {
                        reply: "Qe7"
                    },
                    {
                        info: "Black had to mirror this with Qe2, if they had played d6 then it would continue: 6.d3 f5, reducing black's cover on the kingside when they castle.\
                        <br>Our best response here is d3",
                        targetMove: "d3"
                    },
                    {
                        info: "This forces the knight to retreat",
                        showNextButton: true
                    }
                ],
                [
                    {
                        targetMove: "c4",
                        info: "The Kaufmann Attack is to play c4"
                    },
                    {
                        info: "This prevents black from playing d5",
                        showNextButton: true
                    }
                ],
                [
                    {
                        info: "A completely different approach is to play Nc3",
                        targetMove: "Nc3"
                    },
                    [
                        {
                            reply: "Nxc3"
                        },
                        {
                            info: "We aim for rapid development and castling on the queenside with dxc3",
                            targetMove: "dxc3"
                        },
                        {
                            reply: "Be7"
                        },
                        {
                            info: "Play Be3 to clear the path for castling",
                            targetMove: "Be3"
                        },
                        {
                            reply: "Nd7"
                        },
                        {
                            info: "Play Qd2 to finish clearing the path for castling",
                            targetMove: "Qd2"
                        },
                        {
                            reply: "O-O"
                        },
                        {
                            info: "And now castle queenside",
                            targetMove: "O-O-O"
                        },
                        {
                            info: "We aim to attack on the kingside, our pawns on the c file will help protect our king"
                        }
                    ],
                    [
                        {
                            info: "If black plays Bf5 here instead then we can capture a piece",
                            showNextButton: true
                        },
                        {
                            reply: "Bf5",
                            info: "Play Qe2 to threaten the knight, and pin it against the king",
                            targetMove: "Qe2"
                        },
                        {
                            reply: "Qe7"
                        },
                        {
                            targetMove: "Nd5",
                            info: "Play Nd5, it threatens the queen, but also the pawn on c7, that would create a fork with the rook and king"
                        },
                        {
                            reply: "Qd7"
                        },
                        {
                            info: "Finally play d3 to threaten the knight",
                            targetMove: "d3"
                        },
                        {
                            info: "This line was played in \"Alonso Zapata vs. Viswanathan Anand, 1988\", Viswanathan Anand resigned after 6 moves.",
                            showNextButton: true
                        }
                    ]
                ]
            ]
        ]
    ],
    [
        {
            info: "If white plays d4 here then it is called the \"Steinitz Variation\"",
            targetMove: "d4"
        },
        [
            {
                reply: "Nxe4"
            },
            {
                info: "Play Bd3 here to threaten the knight",
                targetMove: "Bd3"
            },
            [
                {
                    reply: "d5"
                },
                {
                    info: "Play Nxe5",
                    targetMove: "Nxe5"
                },
                [
                    {
                        info: "Black may play Nd7",
                        reply: "Nd7",
                        showNextButton: true
                    }
                ],
                [
                    {
                        info: "Or they may play Bd6",
                        showNextButton: true
                    },
                    {
                        reply: "Bd6",
                    },
                    {
                        info: "From here a complicated sequence is often played in master games.",
                        showNextButton: true
                    },
                    {
                        sequence: [
                            "O-O",
                            "O-O",
                            "c4",
                            "Bxe5",
                            "dxe5",
                            "Nc6",
                            "cxd5",
                            "Qxd5",
                            "Qc2",
                            "Nb4",
                            "Bxe4",
                            "Nxc2",
                            "Bxd5",
                            "Bf5",
                            "g4",
                            "Bxg4",
                            "Be4",
                            "Nxa1",
                            "Bf4",
                            "f5",
                            "Bd5+",
                            "Kh8",
                            "Rc1",
                            "c6",
                            "Bg2",
                            "Rfd8",
                            "Nd2"
                        ]
                    },
                    [
                        {
                            info: "At this point black might play his rook",
                            showNextButton: true
                        },
                        {
                            reply: "Rxd2",
                        },
                        {
                            info: "play Bxd2",
                            targetMove: "Bxd2"
                        },
                        {
                            sequence: [
                                "Rd8",
                                "Bc3",
                                "Rd1+",
                                "Rxd1",
                                "Bxd1",
                            ]
                        },
                        {
                            info: "White and black are roughly equal",
                            showNextButton: true
                        }
                    ],
                    [
                        {
                            info: "Or if black plays h6",
                            showNextButton: true
                        },
                        {
                            reply: "h6",
                        },
                        {
                            info: "Then we play h4",
                            targetMove: "h4"
                        },
                        {
                            info: "White and black are roughly equal",
                            showNextButton: true
                        }
                    ]
                ]
            ],
            [
                {
                    info: "Instead, black might play Nc6",
                    showNextButton: true
                },
                {
                    reply: "Nc6",
                },
                {
                    info: "play Bxe4",
                    targetMove: "Bxe4"
                },
                {
                    reply: "d5"
                },
                {
                    info: "From here you may play either Bd3 or e4",
                    showNextButton: true
                }
            ]
        ],
        [
            {
                info: "But what if black plays exd4",
                showNextButton: true
            },
            {
                reply: "exd4"
            },
            [
                {
                    info: "The best response is e5",
                    targetMove: "e5"
                },
                [
                    {
                        reply: "Qe7"
                    },
                    {
                        info: "White can play Be2 for an advantage",
                        targetMove: "Be2"
                    },
                    {
                        info: "Correct",
                        showNextButton: true
                    }
                ],
                [
                    {
                        info: "let's find out if black played Ne4 instead",
                        showNextButton: true
                    },
                    {
                        sequence: [
                            "Ne4",
                            "Qxd4",
                            "d5",
                            "exd6",
                            "Nxd6",
                            "Nc3",
                            "Nc6",
                            "Qf4",
                        ]
                    },
                    {
                        info: "Black and white are roughly equal from here",
                        showNextButton: true
                    }
                ]
            ],
            [
                {
                    info: "We can also play Bc4",
                    targetMove: "Bc4"
                },
                {
                    info: "This transposes to the Urusov Gambit",
                    showNextButton: true
                }
            ]
        ],
        [
            {
                info: "If Black plays d6 here instead then it turns into the Philidor Defence",
                showNextButton: true
            },
            {
                reply: "d6",
                showNextButton: true
            }
        ]
    ],
    [
        {
            info: "If we play Nc3 here then it is called the \"Three Knights Game of Petrov's Defence\"",
            targetMove: "Nc3"
        },
        [
            {
                reply: "Nc6"
            },
            {
                info: "When black plays Nc6 it has transposed to the \"Four Knights Game\"",
                showNextButton: true
            }
        ],
        [
            {
                info: "If black plays Bb4 or similar then it remains as the Three Knights Game",
                showNextButton: true
            },
            {
                reply: "Bb4",
                showNextButton: true
            }
        ]
    ],
    [
        {
            info: "If we play Bc4 here then it is called the Italian Variation of Petrov's Defence",
            targetMove: "Bc4"
        },
        {
            reply: "Nc6",
            info: "If black plays Nc6 then it has transposed to the Two Knights Defence",
            showNextButton: true
        }
    ],
    {
        info: "This ends our analysis of the Petrov Defense",
        complete: true
    }
];

let targetMove = "";
onPieceClicked(function (squareName) {
    if (Array.isArray(targetMove)) {
        for (let temp of targetMove) {
            if (squareName == sourceOfSan(temp)) {
                return true;
            }
        }
    } else {
        if (targetMove == "") {
            return false;
        }

        if (squareName == sourceOfSan(targetMove)) {
            return true;
        }
    }

    highlightSquareRed(squareName);
    return false;
});

onMoveAttempted(function (san) {
    if (Array.isArray(targetMove)) {
        for (let temp of targetMove) {
            if (san == temp) {
                nextDelayed();
                targetMove = [];
                return true;
            }
        }
    } else {
        if (san == targetMove) {
            nextDelayed();
            targetMove = "";
            return true;
        }
    }

    return false;
});

onNextClicked(function () {
    showNextButton(false);
    next();
});

function nextDelayed() {
    setTimeout(next, 500);
}

let steps = [];
let fenStack = [];

function treeToSteps(root) {
    if (Array.isArray(root) == false) {
        console.error("root must be an array");
    }

    for (let child of root) {
        if (Array.isArray(child)) {
            ///if we find an array then we want to explore it
            ///but once it's over we need to restore the chessboard back
            ///to it's current state
            ///so we generate the current fen, explore the array
            ///and then restore back to the fen
            steps.push({
                pushFen: true
            });

            treeToSteps(child);

            steps.push({
                popFen: true
            });
        } else {
            steps.push(child);
        }
    }
}

treeToSteps(data);


function next() {
    ///sometimes we will have multiple popFen's
    ///this can cause the board to flash
    ///so instead we handle it here
    if (steps.length > 0 && steps[0] != undefined && steps[0].popFen == true) {
        let fen = "";
        while (steps.length > 0 && steps[0] != undefined && steps[0].popFen == true) {
            steps.shift();
            fen = fenStack.pop();
        }

        if (steps.length > 0) {
            fromFen(fen);
            next();
        }

        return;
    }

    if (steps.length == 0) {
        return;
    }

    let step = steps.shift();
    let shouldMoveNext = true;

    if (step.fromFen != undefined) {
        fromFen(step.fromFen);
    }

    if (step.pushFen == true) {
        fenStack.push(toFen());
    }

    if (step.info != undefined) {
        info(step.info);
    }

    if (step.targetMove != undefined) {
        targetMove = step.targetMove;
        shouldMoveNext = false;
    }

    if (step.showNextButton == true) {
        showNextButton(true);
        shouldMoveNext = false;
    }

    if (step.complete == true) {
        complete();
        shouldMoveNext = false;
    }

    if (step.reply != undefined) {
        performMove(step.reply);
        if (shouldMoveNext) {
            nextDelayed();
            shouldMoveNext = false;
        }
    }

    if (step.call != undefined) {
        step.call();
    }

    if(step.sequence != undefined) {
        let whitesTurn = isWhitesTurn();
        let ply = step.sequence.shift();

        if(whitesTurn) {
            info("Play " + ply);
            targetMove = ply;
            shouldMoveNext = false;
        } else {
            performMove(ply);
            shouldMoveNext = false;
            nextDelayed();
        }
        
        if(step.sequence.length > 0) {
            //if there are more moves in the sequence then put the step back in the array
            steps.unshift(step);
        }
    }

    if (shouldMoveNext) {
        next();
    }
}

next();