chess fen plugin for anki

After I discovered anki, a tool to assist in remembering facts, I started to actively use it. Among other uses, I want to keep in memory some important chess positions. To display these positions in anki, I have written a plugin.

In future, it would be possible to install it from the anki plugins repository, write now you have to install it manually. You have to donwload the plugin and unpack it to the anki “plugin” folder. Under Linux, the path is “$HOME/.anki/plugins”

Download chess fen plugin for anki (version 20110627).

The README-file is below, now two screenshots.

1) The text with fen-tags

anki-fen-text.png

2) The fen-tag converted to image

anki-chess-dia.png

The README-file

chess fen
Anki plugin to generate chess diagramms
===========================================================

The plugin converts “fen” tag to a corresponding image.

The original text:

:: Do you like this position?
:: [fen]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1[/fen]

After processing:

:: <img src=”xxxxx” width=”nn” height=”nn” border=”1″ /><br />
:: <b style=”color:gray;font-size:50%;”>[fen]rnbqkbnr/pppppppp
:: /8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1[/fen]</b>

The images are generated and stored in the deck’s media directory.
An image is generated only if it does not exist. The plugin never
deletes images. It is possible to test diagramm generation from
the command line, see the comments inside “chess_fen.py”.

Installation
———————————————————–

Install the fen plugin from the anki plugins repository.

While it is not available there, unpack the archive into
the anki’s plugin folder. Under Linux is it
$HOME/.anki/plugins

License
———————————————————–

The GNU General Public License

Author
———————————————————–

Oleg Parashchenko, olpa@ http://uucode.com/

14 Responses to “chess fen plugin for anki”

  1. Azra Tayyebi Says:

    Hi
    I am a software engineering student. I want write a Anki plug-in for my final project. How can I start? Can you give me some advice?

    Tanks for your consideration,
    Azra Tayyebi

  2. olpa Says:

    As far as I know, there is no documentation how to write plugins. I downloaded and investigated existing plugins, it was enough as starting point.

  3. Will Says:

    Nice plugin. Thanks for creating it.

    If you ever decide to create another chess plugin for Anki please let me know,

    Will

  4. Andrea Says:

    Good Idea! Could you implement the same plug in for Ankidroid?

  5. olpa Says:

    Unfortunately, no. I do not have Android.

  6. Andrea Says:

    No problem, of course I didn’t have to ask you but to Ankidroid’s developers! Anyway, I actually did and and the latest Ankidroid alphas support fen-to-chessboard conversion. We’re also figuring out some interesting attributes for the fen tag, such as orientation=white|black (white by default), to properly flip the board in case you want to remember some positions, variations, opening lines by the black point of view. It should be extremely easy to implement and a huge improvement for chess learners. What do you think?
    Here’s a usage example: [fen orientation=black] … [/fen]

  7. olpa Says:

    > the latest Ankidroid alphas support fen-to-chessboard conversion.
    Great!

    > interesting attributes
    I thought about adding attributes, but finally decided against them. Mostly because I did not want to work on decorations. The only arguable attribute is “orientation”. I decided that for me and other experienced players the orientation is not important, and non-experienced players should learn chess without anki.

    In any case, if you implement attributes, it is great and I support your effort. As for my plugin, I’ll correct it to ignore attributes. This way, android-anki cards would not fail in the classical anki.

  8. Andrea Says:

    > As for my plugin, I’ll correct it to ignore attributes. This way, android-anki cards would not fail in the classical anki.

    Well, that’s something. Thanks for that! Could you let us know when it’s ready? A message here is OK, I’ll enable followup comments notification.

  9. Joey Says:

    Thanks for the plugin! I’ve been using it to study tactics exercises that I wasn’t able to solve on my first attempt as well as positions from my games where I missed a winning move.

    I added a small hack to automatically reverse the board orientation if the FEN indicates that it’s black’s move: https://gist.github.com/2017981#L193

  10. David Says:

    Does this plugin work for Anki 2? It does not seem to be available under addons: https://ankiweb.net/shared/addons/

  11. olpa Says:

    Although it is in my TODO-soon list, I still haven’t tried Anki 2.

  12. Jaxon Says:

    For Anki 2.0, replace everything after # Anki Mode with this code. I messed around a little with the output, removing the displayed FEN notation and adding an indication of the side to move(I wanted to adapt it for use with tactics problems). It’s easy enough to add it back in if you want.

    #
    # Anki mode
    #
    import re
    from anki.hooks import addHook
    from aqt import mw

    load_figures(os.path.join(mw.pm.addonFolder(), ‘chess_fen_media’))

    regexps = {
    “fen”: re.compile(r”\[fen\](?P(.+?))\[/fen\]”, re.DOTALL | re.IGNORECASE),
    “side_to_move”: re.compile(r”(?’ % (s_file, px_width, px_width)
    if regexps[’side_to_move’].search( match.group(’notation’) ).group() == ‘b’:
    s_to_move = ‘Black to move.’
    else:
    s_to_move = ‘White to move.’
    html = html.replace(match.group(), s_img + ” + s_to_move)
    return html

    addHook(”mungeQA”, fen_mungeQA)

  13. Jaxon Says:

    Oops! Trying to paste the code here was a bad idea. I’ve made it available on github:

    https://github.com/jaxonspencer/chess_fen.py/blob/master/chess_fen.py

  14. Edd Says:

    Hi Jaxon,

    Great that you modified it for anki 2.0

    Would it be possible for you to modify the code a little so that the board automatically reverses if the FEN indicates that it’s black’s move. The regular expressions are throwing me somewhat.

Leave a Reply