Coder Social home page Coder Social logo

shogi_addon_for_anki's Introduction

Shogi Visualizer for Anki

This is an addon for Anki (mainly 2.1.x).

You can use following command to view board when you open question card.

[sfen] (sfen format) [/sfen]

[kif] (kif format) [/kif]

(以下日本語)

フリーソフトAnkiを用いて将棋の実力向上を手助けするアドオンです。

将棋倶楽部24、将棋ウォーズ、将棋クエスト等での実戦の振り返りを将棋所を用いて行った際、将棋エンジンの指摘によって課題局面が見つかることがあります。 Ankiとこのアドオンを組み合わせることで、この課題局面の復習効率を高めることができます。

Alt text Alt text

Ankiについての補足

  • Ankiとは

Ankiは単語帳を電子化したようなものです。カードの表面に問題を書き、裏面に答えを書いておき、さらに複数枚のカードを用意すれば、Ankiが適切なタイミングで出題をしてくれます。参考 : http://rs.luminousspice.com/how-to-anki/

  • Anki + 局面画像保存による管理の難点

単にAnkiのデフォルト機能を用いることで、課題局面を保存することも可能です。 ただしその場合、将来的にもう一度将棋所で他の将棋エンジンを用いる際にもう一度局面を入力する必要があり、手間がかかります。

そこで、本アドオンでは局面の入力としてKIFフォーマット、sfenフォーマットに対応し、Anki上で可視化しています。 これによって、後から課題局面を将棋エンジンで検討したい場合にはコピーとペーストのみでその局面を再現することが可能になります。

アドオンの導入方法

(Anki 2.1.xの場合)

  1. Ankiをインストールし、起動する
  2. [ツール] → [アドオン] → [ファイルを見る]
  3. ここにこのレポジトリのAnki2.1ディレクトリ以下にある shogi_visualizationディレクトリ を保存する。
  4. Ankiを再起動する
  5. [ツール] → [アドオン] にshogi_visualization があればOK.

(Anki 2.0.xの場合(非推奨))

  1. Ankiをインストールし、起動する
  2. [ツール] → [アドオン] → [アドオンフォルダを開く]
  3. ここにこのレポジトリのAnki2.0ディレクトリ以下にある shogi_visualization.py を保存する。
  4. Ankiを再起動する
  5. [ツール] → [アドオン] にshogi_visualization があればOK.

Ankiにおけるこのアドオンの使用方法

kif形式の局面を用いる場合、Ankiの編集画面で、このkif形式の局面情報を [kif] と [/kif] でくくります。

次が記入例になります。

[kif] 後手の持駒:飛二 角二 金二 銀四 桂四 香四 歩十八
9 8 7 6 5 4 3 2 1
+---------------------------+
| ・ ・ ・ ・v玉 ・ ・ ・ ・|一
| ・ ・ ・ ・ ・ ・ ・ ・ ・|二
| ・ ・ ・ ・ 金 ・ ・ ・ ・|三
| ・ ・ ・ ・ ・ ・ ・ ・ ・|四
| ・ ・ ・ ・ ・ ・ ・ ・ ・|五
| ・ ・ ・ ・ ・ ・ ・ ・ ・|六
| ・ ・ ・ ・ ・ ・ ・ ・ ・|七
| ・ ・ ・ ・ ・ ・ ・ ・ ・|八
| ・ ・ ・ ・ ・ ・ ・ ・ ・|九
+---------------------------+
先手の持駒:金
先手:
後手:
[/kif]

sfen形式であれば次のようになります。

[sfen]lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL w - 1[/sfen]

将棋所の活用方法

次が作者が便利だと思った使い方になります。

  1. 将棋所をダウンロードし、思考エンジンも好きなものを導入します。
  2. 将棋ウォーズなどから自己対局の棋譜を取得します
  3. 将棋所で棋譜解析をかけます
  4. 良くなかった手と、どう考えれば良かったかを分析します
  5. [編集] -> [局面コピー(KIF/KI2形式)]を選択します
  6. Anki側で[追加]を選択します。
  7. 表面に先ほどコピーした局面を貼り付け、前後に[kif], [/kif]を書きます。
  8. 裏面に考察した内容を書きます

以上の手順で追加を行うことで、自分が間違えやすいであろう問題を追加することができます。

また、一度追加した問題に対してもう一度解析したくなった場合でも、次の手順で将棋所での解析が可能です。

  1. [編集] を押し、kifフォーマットの中身をコピー
  2. 将棋所にペースト

将棋倶楽部24、 将棋ウォーズ、将棋クエスト、それぞれからの利用方法

この節では、各種オンライン対局場から棋譜を取得し、将棋所で検討できる方法について記述します。 なお、2020/5/25現在の情報です。

将棋ウォーズ

  1. 将棋ウォーズにログインする。
  2. マイページを開き、[対局結果・棋譜一覧]をボタンを押下する。
  3. 解析したい棋譜を選択し、[見る]ボタンを押下する。
  4. [ツイート]ボタンを押下し、棋譜のURLをコピーする。
  5. 将棋ウォーズ棋譜保存(http://swks.sakura.ne.jp/wars/kifusave/ )へアクセスする。
  6. 棋譜URLを張り付け、虫眼鏡のアイコンを押下する。
  7. [保存]ボタンを右クリックして、PC内へ保存する。
  8. 保存したファイル内のテキストをコピー、将棋所を開き盤面上をクリックしてCtrl + Vする。

将棋倶楽部24

  1. 東京棋譜 / 大阪棋譜 アプリケーションを開く。
  2. 自分のユーザーでログインする。
  3. 対局者、期間などの条件を入力して[検索]ボタンを押下する。
  4. 解析したい棋譜を選択し、ダブルクリックする。
  5. [棋譜]ボタンを押下する。
  6. 棋譜ウインドウ内のテキストをコピーする。
  7. 将棋所を開き、盤面上をクリックしてCtrl + Vする。

将棋クエスト

  1. 将棋クエスト履歴検索β(https://c-loft.com/shogi/quest/ )へアクセスする。
  2. 自分のユーザー、対局条件を入力して[検索]ボタンを押下する。
  3. 解析したい棋譜を選択し、[clip]を押下する。
  4. 棋譜ウインドウ内のテキストをコピーする。
  5. 将棋所を開き、盤面上をクリックしてCtrl + Vする。

shogi_addon_for_anki's People

Contributors

tokoharu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

timezombi

shogi_addon_for_anki's Issues

Anki 2.1.20+ problem

In Anki2.1.20+, following command cannot to be used (actually, this was deprecated command).

addHook("mungeQA", make_fen_table)

KIF issues with Anki 2.1

I'll preface this bug report with two caveats:

  1. 日本語を学ぶけど、生憎ここで十分じゃありません。
  2. This is probably an Anki 2.0 - 2.1 input field formatting problem.

I have a card template that just puts [kif][/kif] or [sfen][/sfen] around the raw contents of an anki field {{KIF}} or {{SFEN}} respectively. SFEN seems to work just fine - I haven't found any problems yet.

KIF on the other hand seems very fragile. Please consider the two following kifu, one of which is provided by you as a sample, the other of which is the first of a pack of 詰将棋 kifu.

1) Your Sample:

後手の持駒:飛二 角二 金二 銀四 桂四 香四 歩十八  
  9 8 7 6 5 4 3 2 1  
+---------------------------+  
| ・ ・ ・ ・v玉 ・ ・ ・ ・|一  
| ・ ・ ・ ・ ・ ・ ・ ・ ・|二  
| ・ ・ ・ ・ 金 ・ ・ ・ ・|三  
| ・ ・ ・ ・ ・ ・ ・ ・ ・|四  
| ・ ・ ・ ・ ・ ・ ・ ・ ・|五  
| ・ ・ ・ ・ ・ ・ ・ ・ ・|六  
| ・ ・ ・ ・ ・ ・ ・ ・ ・|七  
| ・ ・ ・ ・ ・ ・ ・ ・ ・|八  
| ・ ・ ・ ・ ・ ・ ・ ・ ・|九  
+---------------------------+  
先手の持駒:金  
先手:  
後手:  
  • If I copy this into the Anki field editor, it doesn't work. No board appears, and the 持ち駒 sections are empty. The final raw HTML contents of the field have the newlines removed:
後手の持駒:飛二 角二 金二 銀四 桂四 香四 歩十八 9 8 7 6 5 4 3 2 1 +---------------------------+ | ・ ・ ・ ・v玉 ・ ・ ・ ・|一 | ・ ・ ・ ・ ・ ・ ・ ・ ・|二 | ・ ・ ・ ・ 金 ・ ・ ・ ・|三 | ・ ・ ・ ・ ・ ・ ・ ・ ・|四 | ・ ・ ・ ・ ・ ・ ・ ・ ・|五 | ・ ・ ・ ・ ・ ・ ・ ・ ・|六 | ・ ・ ・ ・ ・ ・ ・ ・ ・|七 | ・ ・ ・ ・ ・ ・ ・ ・ ・|八 | ・ ・ ・ ・ ・ ・ ・ ・ ・|九 +---------------------------+ 先手の持駒:金 先手: 後手:  
  • If I copy this into the Raw HTML editor for the field (bring it up with CTRL+SHIFT+X), it still doesn't work. Same problem as above. The Raw HTML obviously still contains exactly what the sample text kifu contains.
  • If, however, I first copy it into the Raw HTML editor, then copy that into the Anki field editor as normal (first close and re-open the Raw HTML editor before copying again), it works! The final Raw HTML contents of the field also have no newlines, but are full of <div> formatting, which unfortunately seems to be significant for the way the plugin works:
<div>後手の持駒:飛二 角二 金二 銀四 桂四 香四 歩十八 </div> <div> 9 8 7 6 5 4 3 2 1 </div> <div>+---------------------------+ </div> <div>| ・ ・ ・ ・v玉 ・ ・ ・ ・|一 </div> <div>| ・ ・ ・ ・ ・ ・ ・ ・ ・|二 </div> <div>| ・ ・ ・ ・ 金 ・ ・ ・ ・|三 </div> <div>| ・ ・ ・ ・ ・ ・ ・ ・ ・|四 </div> <div>| ・ ・ ・ ・ ・ ・ ・ ・ ・|五 </div> <div>| ・ ・ ・ ・ ・ ・ ・ ・ ・|六 </div> <div>| ・ ・ ・ ・ ・ ・ ・ ・ ・|七 </div> <div>| ・ ・ ・ ・ ・ ・ ・ ・ ・|八 </div> <div>| ・ ・ ・ ・ ・ ・ ・ ・ ・|九 </div> <div>+---------------------------+ </div> <div>先手の持駒:金 </div> <div>先手:</div> <div>後手:</div>

2) My 詰将棋 kifu

# ----  Kifu for Windows V4.01β 棋譜ファイル  ----
# ファイル名:D:\b\temp\M2TOK141\KIFU\1t120600-1.kif
棋戦:1手詰
戦型:なし
手合割:平手  
後手の持駒:飛 角 金四 銀三 桂四 香三 歩十七 
  9 8 7 6 5 4 3 2 1
+---------------------------+
| ・ ・ ・ ・ ・ ・ ・ ・v香|一
| ・ ・ ・ ・ 飛 馬 ・ ・v玉|二
| ・ ・ ・ ・ ・ ・ ・v歩 ・|三
| ・ ・ ・ ・ ・ ・v銀 ・ ・|四
| ・ ・ ・ ・ ・ ・ ・ ・ ・|五
| ・ ・ ・ ・ ・ ・ ・ ・ ・|六
| ・ ・ ・ ・ ・ ・ ・ ・ ・|七
| ・ ・ ・ ・ ・ ・ ・ ・ ・|八
| ・ ・ ・ ・ ・ ・ ・ ・ ・|九
+---------------------------+
先手の持駒:なし
先手:大内延介
後手:最新詰将棋200選
手数----指手---------消費時間--
*作者:大内延介
*発表誌:最新詰将棋200選
   1 3一馬(42)   ( 0:00/00:00:00)
   2 中断         ( 0:00/00:00:00)
まで1手で中断

(the # comment lines don't seem significant)

  • copying into the normal field editor doesn't work, same as before
  • copying into the Raw HTML editor doesn't work, same as before
  • doing the double-copy trick (as above) doesn't work either, but also the plugin crashes with the following message:
Debug info:
Anki 2.1.15 (442df9d6) Python 3.8.1 Qt 5.14.1 PyQt 5.14.1
Platform: Linux
Flags: frz=False ao=True sv=2
Add-ons possibly involved: tokoharu_shogi

Caught exception:
  File "/usr/share/anki/aqt/browser.py", line 98, in data
    return self.columnData(index)
  File "/usr/share/anki/aqt/browser.py", line 238, in columnData
    return self.question(c)
  File "/usr/share/anki/aqt/browser.py", line 292, in question
    return htmlToTextLine(c.q(browser=True))
  File "/usr/share/anki/anki/cards.py", line 120, in q
    return self.css() + self._getQA(reload, browser)['q']
  File "/usr/share/anki/anki/cards.py", line 137, in _getQA
    self._qa = self.col._renderQA(data, *args)
  File "/usr/share/anki/anki/collection.py", line 591, in _renderQA
    d[type] = runFilter(
  File "/usr/share/anki/anki/hooks.py", line 39, in runFilter
    arg = func(arg, *args)
  File "/home/adam/.local/share/Anki2/addons21/tokoharu_shogi/__init__.py", line 328, in make_kif_table
    return kif_re.sub(insert_kif_table, txt)
  File "/home/adam/.local/share/Anki2/addons21/tokoharu_shogi/__init__.py", line 276, in insert_kif_table
    gote_str += get_mochi_kif(line)
  File "/home/adam/.local/share/Anki2/addons21/tokoharu_shogi/__init__.py", line 265, in get_mochi_kif
    ret += format_mochi(pdata[0], val)
<class 'IndexError'>: string index out of range

I have a large collection of 詰将棋 kifu files, and I was hoping to be able to create a deck by parsing out the initial board state as one Field (the question side), and the subsequent moves as another Field (the answer side), but it seems that this plugin doesn't use the kifu plaintext, and it also seems that there are some problems with Anki 2.1.

If you are still interested in maintaining this plugin, I would be very keen to hear back from you, and am willing to provide more details or test any changes as needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.