gnubg python scripting: gnubg.match()

## gnubg.match()のデータを使う

解析が終わったファイルからマッチの情報を取り出し、エラーがあったムーブやcude decisionを取り出してみましょう。gnubgのscriptsフォルダにあるサンプルを参考にして作ってみました。

```py
def exportBad(baseName):
    gnubg.command('load match ' + baseName)
    m = gnubg.match()

    for game in m["games"]:
        print game['info']
        for i, action in enumerate(game["game"]):
            try:
                analysis = action['analysis']
            except KeyError:
                continue

            player = action['player']
            action_type = action["action"]

            skill = analysis.get("skill", None)

            if action_type == "move":
                cube_skill = analysis.get("cube-skill", None)
                if skill:
                    print i, player, action_type, skill
                if cube_skill:
                    print i, player, action_type, cube_skill, "(missed double)"
            elif action_type == "take" or action_type == "drop":
                print i, player, action_type, skill, "(wrong decision)"
```

実行結果はこんな感じです。だいたい合ってそうですね。

```
87027253.sgf
 GNU Backgammon  Position ID: AAAAzLvHAAAAAA
                 Match ID   : 8ArgAIAACAAE
 +13-14-15-16-17-18------19-20-21-22-23-24-+     O: nissis1953
 |                  |   |                  | OOO 8 ポイント
 |                  |   |                  | OOO
 |                  |   |                  | OOO
 |                  |   |                  | OOO
 |                  |   |                  | OOO
v|                  |BAR|                  |     7 ポイントマッチ (キューブ: 1)
 |                  |   |                  |
 |                  |   | X     X          |
 |                  |   | X  X  X          |
 |          X       |   | X  X  X     X    |
 |          X       |   | X  X  X     X    |     1 ポイント
 +12-11-10--9--8--7-------6--5--4--3--2--1-+     X: faresss

{'points-won': 2, 'score-X': 0, 'winner': u'X', 'resigned': False, 'score-O': 0}
5 X move doubtful
16 O move bad
19 X move bad
20 O move doubtful
21 X move doubtful
25 X move bad
28 O move very bad
32 O move very bad
33 X move bad
36 O move very bad
37 X move doubtful
39 X move very bad
{'points-won': 2, 'score-X': 2, 'winner': u'X', 'resigned': False, 'score-O': 0}
1 O move doubtful
4 X move very bad
5 O move very bad
9 O move doubtful (missed double)
11 O move bad (missed double)
15 O move doubtful (missed double)
17 O move bad (missed double)
19 O move very bad (missed double)
21 O move bad
27 O move doubtful (missed double)
{'points-won': 1, 'score-X': 4, 'winner': u'O', 'resigned': False, 'score-O': 0}
1 O move doubtful
2 X move bad
3 O move bad (missed double)
5 O move doubtful (missed double)
7 O move bad (missed double)
8 X move bad
9 O move doubtful
9 O move bad (missed double)
11 O move bad (missed double)
13 O move bad (missed double)
15 O move doubtful (missed double)
{'points-won': 2, 'score-X': 4, 'winner': u'X', 'resigned': False, 'score-O': 1}
0 O move doubtful
3 X move bad
4 O move doubtful
5 X move bad
6 O move very bad
8 O move bad
11 X move doubtful
13 X move doubtful
15 X move doubtful
17 X move bad
18 O move doubtful
18 O move bad (missed double)
20 O move bad (missed double)
23 X move bad
24 O move bad
26 O move bad
40 O move bad
{'points-won': 2, 'score-O': 1, 'winner': u'X', 'score-X': 6, 'resigned': False, 'crawford': True}
1 O move doubtful
9 O move very bad
16 X move very bad
```
![Screenshot from 2016-07-09 21:13:31.png](https://qiita-image-store.s3.amazonaws.com/0/42252/8349e4d8-b17e-49bd-b1f1-f115a989d104.png)

##statsが無い

`help(gnubg.match)`で表示されるヘルプには、統計情報(stats)が入っていることになってますが、どうも見つかりません。設定変えたらなんとかなるかもと思って調べています。

```py
In <6> > m = gnubg.match()

In <7> > games = m['games']

In <9> > type(games)
Out<9> > tuple

In <10> > game0 = games[0]

In <11> > type(game0)
Out<11> > dict

In <12> > game0.keys()
Out<12> > ['info', 'game']
```

つづく