Practice Chess Openings with Anki

Openings are crucial for making progress in chess. It is, unfortunately, not sufficient to learn your own favourite variants because you are not alone on the board. You need a response for all moves of your opponent and you have to memorize these responses. I find it pretty hard to play these opening variants with myself until I remember them. So why not give flash cards, the classical learning tool a try?

Chess pieces on chess board
Photo by Heidi Walley on Unsplash

In the following, we will see how such a learning environment can be built up and permanently maintained with free and open-source software only.

Table Of Contents

Anki as a Flash Card Application

Anki is one of the most popular tools for learning learning things using the flash card approach. The software is:

  • open-source
  • free of charge
  • extensible
  • well documented
  • stable

Of course, you can also put together your own solution to study openings but a real flash-card application like Anki has the advantage advantage that you get the benefits of serious learning software:

  • precisely adjustable time periods for repetition
  • not just "knew"/"didn't know" as a selection option, but four options that you choose according to your own assessment
  • extensive statistics to monitor your own progress
  • ...

Install Anki

Anki can be installed from the Anki download page for Linux, macos and Windows. There are also versions for mobile devices, but I have not tried these.

The Anki Extension "Chess Opening Trainer"

You can create the individual flash-cards (Anki calls them notes) within Anki by hand or you can also import freely accessible decks from the Anki website into your own environment. But I wanted to create the cards automatically from files with opening variations.

In order to achieve this, I had to write an extension for Anki. This extension "Chess Opening Trainer" is available for free from the site https://ankiweb.net/shared/addons (just search for "Chess Opening Trainer"). If you click on the name of the extension, you go to a description page which contains the numerical code code 705507113 of the extension in the Downloads section.

In Anki, open the menu item Tools -> Add-ons select "Get Add-ons ..." and enter the code 705507113.

Installation dialogue

The extension is then installed and after restarting Anki available in the Tools menu as Chess Opening Trainer.

Create opening collections

Chess games are normally saved in PGN files. PGN stands for stands for Portable Game Notation. A PGN file can contain any number of games, and for each move of the game any number of variations can be specified. This means that it is possible to store a complete tree of chess games with variations in a single file.

Experienced chess players probably already have a favourite tool to create PGN files. Here we take a look at how we can create a PGN file as a Lichess study.

General Structure

Opening literature normally contains typical variations that are advantageous for both sides. Mistakes are given in comments rather than variations. In practice, especially in quickly played games, the other side also makes mistakes and the correct reaction on our part is not necessarily obvious. Take for example the Walbrodt-Baird Gambit, a variation of the Italian Game, which begins with the following sequence of moves:

1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. O-O

r . b q k . . r / p p p p . p p p / . . n . . n . . / . . b . . . . . / . . B p P . . . / . . P . . N . . / P P . . P P P P / R N B Q . R K .

White continues the development with castling instead of directly taking back on d4. Black has at most two possibilities to continue here:

    1. ... Nxe4 The best move.
    1. ... dxc3 Also still playable.

The other moves are all bad:

    1. ... d6?
    1. ... d3??
    1. ... d5??
    1. ... Be7?
    1. ... O-O??
    1. ... Bb6??
  • ...

So now I know with Black that White has blundered and stands to lose. But of course I also have to remember how to exploit the mistake. For example, if White castles, the correct reply to 6. ... O-O?? is 7. cxd4. But if this reply - as here - is not obvious, you have to learn it in order not to have to think about it for a long time in a game.

The Anki extension expects a structure of the game collection that embraces this approach. You have to import distinct game collections for black and white. In the collection for white, all white moves have to be moves that we want to play as white, and the black moves must be all possible replies by black, good replies but also mistakes and blunders.

It is important that we only add moves for white that we actually want to play with white. Therefore, the opening repertoire for white will typically contain exactly one first move, for example 1. e4, at least, when we decide to not prepare for other good moves for white (although that would work as well, see below).

The same holds true for the opening repertoire that we create for black, only with sides swapped. And these rules are not only important for the main line of the respective games but also for variants: All variants in the opening repertoire for white are advantageous for white. All variants in the opening repertoire for black are advantageous for black.

Create a Lichess Account

The site lichess.org is a free, ad-free, and open-source chess portal. However, in order to create a study, you need an account. In order to do so, go to the Lichess start pages and click on "Sign in" in the upper right corner. In the following dialogue, click on "Register" and follow the instructions.

Create a Lichess Study

After having registered an account, we can create our first study. Studies can be found in the menu Learn -> Study.

Lichess studies

Study Creation

Select "My studies" in the menu on the left, and then click the green plus sign in the upper right corner to create a new study. As an example, we will create an opening repertoire for black.

Create study

We choose "Opening Repertoire for Black" as the name and leave all other settings untouched for the time being. A click on Start creates the study and a new dialog prompts for the creation of the first chapter.

Create Chapter

A study in Lichess can consist of up to 64 "chapters". A chapter is actually one game, respectively one main line of an opening. For starters we could create three chapters "Open Games 1. e4 e5", "Closed Games 1. d4 d4" and "Irregular Openings". Since we are creating an opening repertoire for black, we choose "Black" as orientation so that the board is rotated and we see the position from black's point of view.

Create chapter

You can add more chapters by clicking the button "Add chapter" below the chapter list on the left side. Once we have created all three chapters, we can select a chapter by clicking on it. Let's start with the third chapter "Irregular Openings". We choose the Zukertort opening as the main variant and enter the moves 1. Nf3 d5 2. d4 Nf6 3. Bf4 e6 ein. That will later create three flash-cards in Anki with the questions "1. Nf3", "1. Nf3 d5 2. d4" and "1. Nf3 d5 2. d4 Nf6 3. Bf4". The answers are the corresponding black moves, that is "1. ... d5", "2. ... d4" , and "3. ... e6". Additionally, a diagram of the board will be created.

Create Variants

Of course, there are other possible reactions by white. For example, after 2. ... Nf6, white could also continue with 3. c4, and we need a reply for this variant, too. To do so, select 2. ... Nf6 in the list of moves on the right.

Select move

If we now move 3. c4 with white, a new variant is created and we can enter our reply 3. ... c6. The variant looks like this:

First main variant

In Anki, this will trigger the creation of another flash-card with the "question" 1. Nf3 d5 2. d4 Nf6 3. c4 and the "answer" 3. ... c6.

Let's assume that we want to broaden our repertoire at this point and also prepare 3. ... e6. In terms of flash-cards, we want two have two answers on this card: 3. ... c6 and 3. ... e6. That is easy to do in Lichess becayse you can arbitrarily nest variants. We select the move 3. c4 in the variant and move 3. ... e6. This will results in a subvariant:

Subvariant

Annotations, Arrows, and Circles

Maybe we want to add a comment to the answer that helps us remembering the correct answer. In order to do so, we click the speech bubble on the toolbar below the board and enter a comment.

Comment

If we find this move really fancy we may want to annotate it with "!?" as an interesting move. Click the icon !? in the toolbar and select the symbol !?:

Annotate moves

Doing this graphically is, of course, a lot nicer. We can mark the pawn on d5 with a green circle by right-clicking it. Then we draw a green arrow from the knight on f6 to the pawn on d5 by dragging the mouse with the right mouse button held down. We repeat that with an arrow from e6 to d5. For the bishop's diagonal from f8 to d4 we additionally press Ctrl while drawing the arrow with the right mouse button.

Drawing arrows and circles

All these graphical elements will be visible on the flash-cards. You can explore further possibilities in the Lichess documentation.

Further First Moves of White

There are, of course, further irregular openings than 1. Nf3, for example the English opening 1. c4. Normally, variations are entered by selecting the move before the variation starts, and then just enter the new move. But for the first move there is no move before. So you have to navigate to the beginning of the game either by using the arrows in the toolbar under the move list or by using the cursor keys on your keyboard.

The Opening Database

Clicking on the book icon in the same toolbar displays Lichess' opening database. With the help of this database it is easy to find further popular opening variants. By navigating to the beginning of the game we can then see that the next popular moves other than 1. e4, 1. d4, and 1. Nf3 are the openings 1. c4, 1. e3, 1. g3, 1. b3:

Opening database

Because we have selected the tab "Lichess", we see the statistics of games played on Lichess. With the tab "Masters" only grandmaster games are taken into account, and the tab "Player" selects only own games. The opening database is not only available for the first move but also for subsequent moves, provided that there has been played a sufficient number of games with the particular sequence of moves in question.

Exporting the Opening Collection

In order to use the opening collection on the local computer, it has to be exported from Lichess. Click the share icon in the toolbar below the board and click "Study PGN" to download the study. The PGN file in the computer's download directory will be called something like lichess_study_NAME_ETC_JAHR_MONAT_TAG.pgn.

Share a study

Import the Opening Collection into Anki

Time to import the opening collection into Anki and to convert it into flash-cards for studying. Before we can do that, we have to create decks that the flash-cards can be imported into because initially, there is only the default deck of Anki.

Anki initial state

Creating Decks in Anki

The structure of decks is pretty much a matter of personal taste. My suggestion is a hierarchical structure. Click the button Create Deck at the bottom.

Create deck

Choose Chess::Opening::White as the name of the deck. The double colons act as a path separator in Anki. After you have created the deck Chess::Opening::Black in the same manner, you can expand the decks and will find the following structure:

Deck summary

You can study each deck in Anki individually. That means that you can learn white and black openings individually. You can also select the deck Chess::Opening at one level above and learn white and black openings at once. And if there are further decks like Chess::Midgame and Chess::Endgame you can learn all chess topics together.

Import PGN

No! Do not click on Import File in the decks overview. That is a general function of Anki and has nothing to do with this chess add-on. The import of the PGN file is done via the menu entry Tools -> Chess Opening Trainer.

Import PGN file

The colour selection white/black determines the point of view. We select black because the study PGN contains the best moves for black. Accordingly, the deck should be Chess::Opening::Black.

With a click on the button Select files you select one or more game collections in PGN format. If you want to select multiple files it is better to keep them in a dedicated, separate dicretory so they are easier to select.

At the bottom you have to select the note type. The note type must have exactly two fields, one for the front and one for the back of the card. This is the case for the note type "Basic" that ships with Anki.

A click on OK starts the import. Normally, after a short time, you should see an overview of the created, modified, and deleted objects.

Import status

Study Openings

After a successful import, the deck overview in Anki should look like this:

Deck overview

We now have the choice to study all cards from the topic chess, or just those from the topic chess openings or just openings for black or white. For the time being, that makes no difference because only openings for black have been imported.

We decide to learn only chess openings, both for white and black. A click on "Opening" will show a summary of the selected deck.

Deck summary

A click on Study now starts a new session and displays a position from the opening repertoire with the move sequence leading to it. Additionally, a diagram with the position after the move sequence is displayed, for example after 1. e4.

Question **1. e4**

The answer does not have to be typed in but only be remembered. Since we had decided to always try to play open games, the correct answer is 1. ... e5. You can assess it with a click on Show Answer.

Answer **1. ... e5**

If you have given the wrong answer you should click Again. That will put the card back into the deck so that it gets presented again during this session.

If you have known the answer, you can give your assessment of the difficulty of the question with the buttons Hard, Good, and Easy. That controls directly when the card will be presented again. The time until it gets presented is displayed above the buttons.

You can now repeat this until all tasks for today have been successfully finished or you give up.

By default, Anki will ask for a maximum of 20 new cards per day. But that can be changed. A click on the settings icon right of the deck name in the decks overview opens a context menu with one entry Options. A click on it opens the deck options where you can change the number of new cards per day from 20 to another value.

Studying with Anki is mostly self-explanatory. If you have questions, you can always consult the Anki Manual.

Bugs and Caveats

Hint: For all of the following issues, you will find a ticket in the source code repository on GitHub at https://github.com/gflohr/anki-chess-opening-trainer/issues. You are welcome to leave a comment there.

Deleting While Importing

When you import a game collection into a deck, a complete synchronization takes place. That can not only result in the creation or modification of notes but also into deletion. Should the position for a particular note not be found in the imported files, the note gets deleted, including a possibly saved learning progress.

You therefore have to take care to always import all PGN files. That is easiest to achieve if you have a dedicated directory for each deck and keep all PGNs for that deck there. This makes it also easier to select all files at once.

See https://github.com/gflohr/anki-chess-opening-trainer/issues/4!

Modifications of the Answer

If you want to learn an additionalor or a new answer for a particular sequence of moves, you will run into a problem. Although the answer has changed, the learning progress saved with the question will not change, although the answer is a new one. Given that you have studied only the Italian Game 1. e4 e5 2. Nf3 Sc6 3. Bc4 until now and want to add the the Spanish Game 1. e4 e5 2. Nf3 Nc6 3. Bc5 to your repertoire, the expected answer is 3. Bc4 and 3. Bc5. At the moment, Anki will not notice this change and will not consider the card as new. That means that it may take time until the card is presented again.

You run into the same problem if you have just modified the answer, for instance, when you switch from Italian to Spanish.

The problem can be solved but the solution is not totally trivial. Therefore, for the time being, you have to delete the card 1. e4 e5 2. Nf3 Nc6 before you import a new game collection. That will also delete the learning progress and the card will be considered as a new one.

See https://github.com/gflohr/anki-chess-opening-trainer/issues/3!

Transpositions are Ignored

At the moment, a note is identified by the exact sequence of moves leading to the corresponding position. If two sequences result in the same position, two separate notes will be created for it.

A simple solution would be to simply ignore positions that had aready been encountered and not generate a note for it. But that would also discard comments, annotations, arrows and so on which is maybe not desired. At the moment, the recommended solution - that is also known from chess literature - is to add a comment like "this leads to the same position as after moving XYZ".

See https://github.com/gflohr/anki-chess-opening-trainer/issues/2!

Ignore the First Few Moves

With increasing experience, the first few moves of an opening will not pose a challenge anymore. When you learn the Spanish Game, you will probably not need a card for the best move after 1. e4 e5. This will even be more apparent for advanced players. If somebody dares to approach the Najdorf variant of the Sicilian Defence, at least the first five moves are of not interest at alll.

There are basically two possible solutions. Moves (nodes in the game tree) could be marked as irrelevant by a special comment like "IGNOREME". That looks like a hack and it also is one.

Alternatively, an import parameter could control the minimum depth for generating notes. But that would be a global setting for all files being imported into the deck. But this global setting would probably not always be correct. For the time being, it is best to just ignore the problem by clicking away trivial questions. They will then vanish automatically after a short time.

See https://github.com/gflohr/anki-chess-opening-trainer/issues/1!

Conclusion

This Anki add-on gives you a nice tool for studying openings or an entire opening repertoire. Grandmasters have probably developed other techniquess for studying openings but the flash-card approach fits well for beginners and occasional players and it is based on an established and well-researched learning method.

You like this add-on and want to encourage its further development? Feedback is welcome:

By the way, the smart analysis of the Walbrodt-Baird Gambit should not fool you into thinking that I have a profound chess knowledge. Quite the opposite! I am a lousy chess player and you can prove that by challenging me for a game on my Lichess page. My nick on the site is lisco.

Happy studying and good luck with your chess games!

Leave a comment
This website uses cookies and similar technologies to provide certain features, enhance the user experience and deliver content that is relevant to your interests. Depending on their purpose, analysis and marketing cookies may be used in addition to technically necessary cookies. By clicking on "Agree and continue", you declare your consent to the use of the aforementioned cookies. Here you can make detailed settings or revoke your consent (in part if necessary) with effect for the future. For further information, please refer to our Privacy Policy.