English Opening Trainer

Details

Author:Mark
Rating:
Difficulty:Beginner
Date:2nd February 2021
Description:A trainer to help you learn and memorize all the variations of the English Opening.

Code

//Please feel welcome to copy this code for your own creations.

//fromFen("rnbqkbnr/pppppppp/8/8/2P5/8/PP1PPPPP/RNBQKBNR w KQkq - 0 1");
let root = [
    "c4",
    {
        "info": "This is the English Opening"
    },
    [
        "c5",
        {
            "info": "This is the Symmetrical Defense"
        },
        [
            "b4",
            {
                "info": "This is the Symmetrical Defense (Wing Gambit)"
            }
        ],
        [
            "Nf3",
            "Nf6",
            [
                "g3",
                "b6",
                "Bg2",
                "Bb7",
                "O-O",
                "e6",
                "Nc3",
                "Be7",
                {
                    "info": "This is the Symmetrical Hedgehog system"
                },
                "d4",
                "cxd4",
                "Qxd4",
                "d6",
                "Rd1",
                "a6",
                "b3",
                "Nbd7",
                {
                    "info": "This is the Symmetrical Flexible Hedgehog system"
                }
            ],
            [
                "d4",
                {
                    "info": "This is the Anti-Benoni"
                },
                "cxd4",
                "Nxd4",
                "e6",
                {
                    "info": "This is the Anti-Benoni Variation"
                },
                "Nc3",
                "Nc6",
                {
                    "info": "This is the Anti-Benoni (Geller)"
                }
            ]
        ],
        [
            "Nc3",
            {
                "info": "This is the Asymmetrical Variation"
            },
            [
                "Nf6",
                [
                    "g3",
                    "d5",
                    "cxd5",
                    "Nxd5",
                    {
                        "info": "This is the Asymmetrical (Rubinstein)"
                    }
                ],
                [
                    "Nf3",
                    "d5",
                    "cxd5",
                    "Nxd5",
                    {
                        "info": "This is the Asymmetrical (Three Knights)"
                    },
                    "g3",
                    "Nc6",
                    "Bg2",
                    "e6",
                    "O-O",
                    "Be7",
                    {
                        "info": "This is the Asymmetrical (Keres)"
                    }
                ]
            ],
            [
                "Nc6",
                {
                    "info": "This is the Symmetrical (Two Knights)"
                },
                [
                    "Nf3",
                    "Nf6",
                    {
                        "info": "This is the Symmetrical (Four Knights)"
                    }
                ],
                [
                    "g3",
                    {
                        "info": "This is the Symmetrical (Fianchetto)"
                    },
                    "g6",
                    "Bg2",
                    "Bg7",
                    {
                        "info": "This is the Ultra-Symmetrical Variation"
                    },
                    [
                        "e4",
                        {
                            "info": "This is the Ultra-Symmetrical (Botvinnik)"
                        }
                    ],
                    [
                        "e3",
                        "e5",
                        {
                            "info": "This is the Ultra-Symmetrical (Reversed Botvinnik)"
                        }
                    ],
                    [
                        "Nf3",
                        {
                            "info": "This is the Ultra-Symmetrical"
                        },
                        [
                            "e5",
                            {
                                "info": "This is the Ultra-Symmetrical (Russian)"
                            }
                        ],
                        [
                            "Nf6",
                            {
                                "info": "This is the Ultra-Symmetrical Variation"
                            },
                            "O-O",
                            "O-O",
                            [
                                "b3",
                                {
                                    "info": "This is the Ultra-Symmetrical (Double Fianchetto)"
                                }
                            ],
                            [
                                "d4",
                                {
                                    "info": "This is the Ultra-Symmetrical (Mecking)"
                                }
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ],
    [
        "e5",
        {
            "info": "This is the Reversed Sicilian"
        },
        [
            "g3",
            "h5",
            {
                "info": "This is the Reversed Sicilian (Drill)"
            }
        ],
        [
            "Nf3",
            {
                "info": "This is the Reversed Sicilian (Nimzovich)"
            },
            "e4",
            {
                "info": "This is the Reversed Sicilian (Flohr)"
            }
        ],
        [
            "Qa4",
            {
                "info": "This is the Reversed Sicilian (English Queen)"
            }
        ],
        [
            "Nc3",
            {
                "info": "This is the Reversed Sicilian"
            },
            [
                "Bb4",
                {
                    "info": "This is the  Reversed Sicilian (Vienna)"
                }
            ],
            [
                "d6",
                [
                    "g3",
                    "c6",
                    {
                        "info": "This is the Reversed Sicilian (Keres)"
                    }
                ],
                [
                    "Nf3",
                    "Bg4",
                    {
                        "info": "This is the Reversed Sicilian (Smyslov)"
                    }
                ]
            ],
            [
                "Nf6",
                {
                    "info": "This is the Reversed Sicilian (Two Knights)"
                },
                [
                    "Nf3",
                    "e4",
                    "Ng5",
                    "b5",
                    {
                        "info": "This is the Reversed Sicilian (Bellón)"
                    }
                ],
                [
                    "g3",
                    {
                        "info": "This is the Carls"
                    },
                    [
                        "d5",
                        {
                            "info": "This is the Carls (Reversed Dragon)"
                        }
                    ],
                    [
                        "Bb4",
                        {
                            "info": "This is the Carls (Smyslov)"
                        }
                    ],
                    [
                        "c6",
                        {
                            "info": "This is the Carls (Keres)"
                        }
                    ],
                    [
                        "g6",
                        {
                            "info": "This is the Carls (Bremen)"
                        },
                        "Bg2",
                        "Bg7",
                        [
                            "d3",
                            {
                                "info": "This is the Carls (Closed)"
                            }
                        ],
                        [
                            "e3",
                            "d6",
                            "Nge2",
                            "Be6",
                            {
                                "info": "This is the Carls (Hort)"
                            }
                        ]
                    ]
                ]
            ],
            [
                "Nc6",
                {
                    "info": "This is the Closed Reversed Sicilian"
                },
                [
                    "g3",
                    {
                        "info": "This is the Closed Reversed Sicilian (Carls)"
                    },
                    "g6",
                    "Bg2",
                    [
                        "Bg7",
                        {
                            "info": "This is the Closed Reversed Sicilian (Taimanov)"
                        },
                        [
                            "e3",
                            "d6",
                            "Nge2",
                            "Be6",
                            {
                                "info": "This is the Closed Reversed Sicilian (Hort)"
                            }
                        ],
                        [
                            "d3",
                            {
                                "info": "This is the Closed Reversed Sicilian"
                            },
                            "d6",
                            "e4",
                            {
                                "info": "This is the Closed Reversed Sicilian (Botvinnik)"
                            }
                        ]
                    ],
                    [
                        "Be6",
                        {
                            "info": "This is the Closed Reversed Sicilian (Tröger)"
                        }
                    ]
                ],
                [
                    "e3",
                    "Nf6",
                    "b3",
                    "d6",
                    {
                        "info": "This is the Closed Reversed Sicilian (Amsterdam)"
                    }
                ],
                [
                    "Nf3",
                    {
                        "info": "This is the Three Knights System"
                    },
                    [
                        "f5",
                        {
                            "info": "This is the Three Knights System (Dutch)"
                        }
                    ],
                    [
                        "Nf6",
                        {
                            "info": "This is the Four Knights System"
                        },
                        [
                            "a3",
                            {
                                "info": "This is the Four Knights System (Marini)"
                            }
                        ],
                        [
                            "e4",
                            {
                                "info": "This is the Four Knights System (Nimzovich)"
                            }
                        ],
                        [
                            "d4",
                            [
                                "e4",
                                {
                                    "info": "This is the Four Knights System (Bradley Beach)"
                                }
                            ],
                            [
                                "exd4",
                                "Nxd4",
                                "Bb4",
                                "Bg5",
                                "h6",
                                {
                                    "info": "This is the Four Knights System (Nenarokov)"
                                }
                            ]
                        ],
                        [
                            "d3",
                            {
                                "info": "This is the Four Knights System (Capablanca)"
                            }
                        ],
                        [
                            "e3",
                            "Bb4",
                            "Qc2",
                            [
                                "O-O",
                                "Nd5",
                                "Re8",
                                "Qf5",
                                {
                                    "info": "This is the Four Knights System (Stean)"
                                }
                            ],
                            [
                                "Bxc3",
                                {
                                    "info": "This is the Four Knights System (Romanishin)"
                                }
                            ]
                        ],
                        [
                            "g3",
                            {
                                "info": "This is the Four Knights System (Fianchetto)"
                            }
                        ]
                    ]
                ]
            ]
        ]
    ],
    [
        "g6",
        {
            "info": "This is the Snake variation, aka the Great Snake variation"
        },
        "e4",
        "e5",
        {
            "info": "This is the Snake (Adorjan) Defence"
        }
    ],
    [
        "f5",
        {
            "info": "This is the Anglo-Dutch Defense"
        },
        [
            "e4",
            {
                "info": "This is the Anglo-Dutch, Hickmann Gambit"
            }
        ],
        [
            "b4",
            {
                "info": "This is the Anglo-Dutch, Polish Variation"
            }
        ],
        [
            "g4",
            {
                "info": "This is the Anglo-Dutch, Wade Gambit, aka Grob attack"
            }
        ],
        [
            "Nf3",
            "d6",
            "e4",
            {
                "info": "This is the Anglo-Dutch, Chabanon Gambit"
            }
        ]
    ],
    [
        "b5",
        {
            "info": "This is the Jaenisch Gambit"
        }
    ],
    [
        "d5",
        {
            "info": "This is the Anglo-Scandinavian Defense"
        },
        "cxd5",
        "e6",
        {
            "info": "This is the Anglo-Scandinavian, Löhn Gambit"
        }
    ],
    [
        "g5",
        {
            "info": "This is the Myers' Defense"
        }
    ],
    [
        "c6",
        {
            "info": "This is the Anglo-Slav Defense"
        },
        [
            "d4",
            "d5",
            {
                "info": "This transposes to the Slav Defense"
            }
        ],
        [
            "e4",
            "d5",
            {
                "info": "This transposes to the Caro–Kann Defence"
            }
        ],
        [
            "Nf3",
            "d5",
            [
                "g3",
                "Nf6",
                "Bg2",
                "g6",
                {
                    "info": "This is the Anglo-Slav (Irregular)"
                }
            ],
            [
                "b3",
                {
                    "info": "This is the Caro–Kann Defence System 2, (aka Bogolubov)"
                },
                "Nf6",
                [
                    "Bb2",
                    [
                        "Bf5",
                        {
                            "info": "This is the Bogolubov (New York)"
                        }
                    ],
                    [
                        "Bg4",
                        {
                            "info": "This is the Bogolubov (Capablanca)"
                        }
                    ]
                ],
                [
                    "g3",
                    [
                        "Bf5",
                        {
                            "info": "This is the Bogolubov (London)"
                        },
                        "Bg2",
                        "e6",
                        "Bb2",
                        "Nbd7",
                        {
                            "info": "This is the Bogolubov (Réti)"
                        }
                    ],
                    [
                        "Bg4",
                        {
                            "info": "This is the Bogolubov (Torre)"
                        }
                    ]
                ]
            ]
        ]
    ],
    [
        "e6",
        {
            "info": "This is the Agincourt Defense"
        },
        "Nf3",
        [
            "Nf6",
            "g3",
            "a6",
            {
                "info": "This is the  Romanishin Gambit"
            }
        ],
        [
            "d5",
            {
                "info": "This is the Agincourt (King's Knight)"
            },
            [
                "b3",
                "Nf6",
                "Bb2",
                "c5",
                "e3",
                {
                    "info": "This is the  Whimpey System"
                }
            ],
            [
                "g3",
                [
                    "c6",
                    {
                        "info": "This is the  Kurajica Defense"
                    }
                ],
                [
                    "Nf6",
                    {
                        "info": "This is the Neo-Catalan"
                    },
                    "Bg2",
                    [
                        "c5",
                        "b3",
                        "Nc6",
                        "O-O",
                        "Be7",
                        {
                            "info": "This is the Neo-Catalan (Tarrasch)"
                        }
                    ],
                    [
                        "Bd6",
                        {
                            "info": "This is the Neo-Catalan (Bogo-Catalan)"
                        }
                    ],
                    [
                        "dxc4",
                        {
                            "info": "This is the Neo-Catalan (Accepted)"
                        }
                    ],
                    [
                        "Be7",
                        {
                            "info": "This is the Neo-Catalan"
                        },
                        [
                            "O-O",
                            {
                                "info": "This is the Neo-Catalan (Declined)"
                            }
                        ],
                        [
                            "b3",
                            "O-O",
                            "Bb2",
                            "a5",
                            {
                                "info": "This is the Neo-Catalan (Bogolubov)"
                            }
                        ]
                    ]
                ]
            ]
        ]
    ],
    [
        "Nf6",
        {
            "info": "This is the Anglo-Indian"
        },
        [
            "b4",
            {
                "info": "This is the Anglo-Indian (Polish)"
            }
        ],
        [
            "Nf3",
            {
                "info": "This is the Anglo-Indian (King's Knight)"
            },
            "g6",
            "g3",
            "Bg7",
            "Bg2",
            "O-O",
            {
                "info": "This is the Anglo-Indian (King's Fianchetto)"
            }
        ],
        [
            "Nc3",
            {
                "info": "This is the Anglo-Indian (Queen's Knight)"
            },
            [
                "d5",
                {
                    "info": "This is the Anglo-Grünfeld"
                },
                "cxd5",
                "Nxd5",
                [
                    "g3",
                    [
                        "g6",
                        "Bg2",
                        [
                            "Nb6",
                            {
                                "info": "This is the Anglo-Grünfeld (Czech)"
                            }
                        ],
                        [
                            "Nxc3",
                            {
                                "info": "This is the Anglo-Grünfeld (Smyslov)"
                            }
                        ]
                    ],
                    [
                        "c5",
                        "Bg2",
                        "Nc7",
                        {
                            "info": "This is the Anglo-Grünfeld (Rubinstein)"
                        }
                    ]
                ],
                [
                    "Nf3",
                    "g6",
                    "g3",
                    "Bg7",
                    "Bg2",
                    "e5",
                    {
                        "info": "This is the Anglo-Grünfeld (Korchnoi)"
                    }
                ]
            ],
            [
                "e6",
                {
                    "info": "This is the Hedgehog system"
                },
                [
                    "Nf3",
                    [
                        "b6",
                        {
                            "info": "This is the Hedgehog (Queen's Indian)"
                        },
                        "e4",
                        "Bb7",
                        "Bd3",
                        {
                            "info": "This is the Hedgehog (Romanishin)"
                        }
                    ],
                    [
                        "Bb4",
                        {
                            "info": "This is the Hedgehog (Nimzovich)"
                        }
                    ]
                ],
                [
                    "e4",
                    {
                        "info": "This is the Mikenas"
                    },
                    [
                        "d5",
                        {
                            "info": "This is the Mikenas (French)"
                        },
                        "e5",
                        {
                            "info": "This is the Mikenas (Flohr)"
                        }
                    ],
                    [
                        "Nc6",
                        {
                            "info": "This is the Mikenas (Kevitz)"
                        }
                    ],
                    [
                        "c5",
                        {
                            "info": "This is the Mikenas (Sicilian)"
                        },
                        "e5",
                        "Ng8",
                        {
                            "info": "This is the Mikenas (Nei)"
                        }
                    ]
                ]
            ]
        ]
    ]
];

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

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

    highlightSquareRed(squareName);
    return false;
});

onMoveAttempted(function (san) {
    if (typeof targetMove == "string") {
        if (san == targetMove) {
            current.index++;
            setTimeout(next, 50);
            return true;
        }
    } else if (Array.isArray(targetMove)) {
        for (let temp of targetMove) {
            if (san == temp) {
                for (let i = current.index; i < current.length; i++) {
                    if (current[i][0] == san) {
                        current[i].parent = current;
                        current = current[i];
                        current.index = 1;
                        break;
                    }
                }

                setTimeout(next, 50);
                return true;
            }
        }
    } else {
        throw new Error();
    }

    return false;
});

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

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

function onUndoClicked() {
    undo();

    if (current.index > 0) {
        current.index--;

        if (current.index > 0 && current[current.index].info != undefined) {
            current.index--;
        }
    }

    if (current.index == 0) {
        if (current.parent != undefined) {
            current = current.parent;
        } else {
            //showButton("undo", false);
        }
    }

    next();
}

let current = root;
current.index = 0;

let preInfo = "";

createButton("Undo", onUndoClicked);
showButton("Undo", false);
let undoButtonVisible = false;

function next() {
    let showUndoButton = current != root || current.index > 0;
    if (undoButtonVisible != showUndoButton) {
        showButton("Undo", showUndoButton);
        undoButtonVisible = showUndoButton;
    }

    if (preInfo != "") {
        preInfo += "<br><br>";
    }

    if (current.index >= current.length) {
        info(preInfo + "End of the line");
        preInfo = "";
        return;
    }

    let step = current[current.index];

    if (typeof step == "string") {
        if (isWhitesTurn()) {
            info(preInfo + "White to play <b>" + currentMoveNumber() + "." + step + "</b>");
        } else {
            info(preInfo + "Black to play <b>" + currentMoveNumber() + "..." + step + "</b>");
        }

        targetMove = step;
        preInfo = "";
    } else if (Array.isArray(step)) {
        ///assume that the rest of the steps in the current array are also arrays
        //i.e. different options from this point

        let possibleSteps = [];
        for (let i = current.index; i < current.length; i++) {
            //assume that the first step in every array is a string
            //otherwise it would be seperated out into an array at the previous level
            possibleSteps.push(current[i][0]);
        }

        targetMove = possibleSteps;

        if (isWhitesTurn()) {
            possibleSteps = possibleSteps.map(x => "<li><b>" + currentMoveNumber() + "." + x + "</b></li>");
            info(preInfo + "White can play: <ul>" + possibleSteps.join("") + "</ul>");
        } else {
            possibleSteps = possibleSteps.map(x => "<li><b>" + currentMoveNumber() + "..." + x + "</b></li>");
            info(preInfo + "Black can play: <ul>" + possibleSteps.join("") + "</ul>");
        }

        preInfo = "";
    } else {
        if (step.info != undefined) {
            preInfo = step.info;
            current.index++;
            next();
        }
    }
}

next();