LoginSignup
13
15

More than 5 years have passed since last update.

囲碁プロ棋士の棋譜を眺める

Last updated at Posted at 2017-08-24

wangjinzhuo/pgd1にはプロ棋士の棋譜データ約26万局がSGF形式2で保存されています.

SGFとは

Smart Game Format(Smart Go Format)の略称で囲碁の棋譜を保存するためによく利用されています.(というより囲碁以外で見たことないような...)
下記はSGFデータの例2で,KMがコミとか,BやWがそれぞれ黒や白を表していて[]内の2文字が位置を表しています.

 (;FF[4]GM[1]SZ[19]
 GN[Copyright goproblems.com]
 PB[Black]
 HA[0]
 PW[White]
 KM[5.5]
 DT[1999-07-21]
 TM[1800]
 RU[Japanese]
 ;AW[bb][cb][cc][cd][de][df][cg][ch][dh][ai][bi][ci]
 AB[ba][ab][ac][bc][bd][be][cf][bg][bh]
 C[Black to play and live.]
 (;B[af];W[ah]
 (;B[ce];W[ag]C[only one eye this way])
 (;B[ag];W[ce]))
 (;B[ah];W[af]
 (;B[ae];W[bf];B[ag];W[bf]
 (;B[af];W[ce]C[oops! you can't take this stone])
 (;B[ce];W[af];B[bg]C[RIGHT black plays under the stones and lives]))
 (;B[bf];W[ae]))
 (;B[ae];W[ag]))

対局データのダウンロード

git clone https://github.com/wangjinzhuo/pgd.git # データセットのダウンロード
pip install -U sgf # sgfパーサーのインストール

対局の読み込み

下記のように記述することで対局を読み込むことができます.

# -*- coding: utf-8 -*-
import sgf

fpath = u"All/(嘉永2年)1849-10-8_None_太田雄藏 七段_None_本因坊秀策 六段_None_B+4目.sgf"
print(fpath)
game_tree = sgf.parse(open(fpath).read()).children[0]
node = game_tree.root
while node:
    print(node.properties)
    node = node.next

実行結果

All/(嘉永2年)1849-10-8_None_太田雄藏 七段_None_本因坊秀策 六段_None_B+4目.sgf
{'SZ': ['19'], 'C': ['\xcc\xab\xcc\xef\xd0\xdb\xb2\xd8 = Ota Yuzo, \xb1\xbe\xd2\xf2\xb7\xbb\xd0\xe3\xb2\xdf = Honinbo Shusaku'], 'PW': ['\xb1\xbe\xd2\xf2\xb7\xbb\xd0\xe3\xb2\xdf \xc1\xf9\xb6\xce'], 'RE': ['B+4\xc4\xbf'], 'PB': ['\xcc\xab\xcc\xef\xd0\xdb\xb2\xd8 \xc6\xdf\xb6\xce'], 'PC': [''], 'FF': ['3'], 'DT': ['(\xbc\xce\xd3\xc02\xc4\xea)1849-10-8'], 'HA': ['\xcf\xc8\xcf\xe0\xcf\xc8, \xcf\xc8\xb7\xac']}
{'B': ['qd']}
{'W': ['dc']}
{'B': ['pq']}
{'W': ['qo']}
...
{'W': ['rn']}
{'B': ['sm']}
{'W': ['jb']}
{'B': ['sp']}
{'W': ['no']}
{'C': ['\xb9\xb2289\xca\xd6. \xba\xda4\xc4\xbf\xca\xa4.'], 'B': ['sq']}

GNU GOで観戦

GNU GO3を使えばCUI形式で盤面に表示することもできます.
macOSには下記コマンドでインストールできます.

brew tap homebrew/games
brew install gnu-go

100手目まで表示したい場合は下記のように記述することで表示できます.

$ gnugo --mode ascii -l "All/(嘉永2年)1849-10-8_None_太田雄藏 七段_None_本因坊秀策 六段_None_B+4目.sgf" -L 100 --quiet

Beginning ASCII mode game.

Board Size:   19
Handicap      0
Komi:         5.5
Move Number:  99
To Move:      white
Computer player: White
white(100): Q12

    White (O) has captured 1 pieces
    Black (X) has captured 3 pieces

    A B C D E F G H J K L M N O P Q R S T        Last move: White Q12
 19 . . . . . . . . . . . . . . . . . . . 19
 18 . . . . . O O . . . . . . . . . O . . 18
 17 . O O O O X O X . . X . . . O . . . . 17
 16 . X O X O X X X . + . . O . . + X . . 16
 15 . . X X X O . . . . . . . . . X . . . 15
 14 . . X . O . . . . . . . . . . . . . . 14
 13 . X X X X O . . . . . . . . . . . . . 13
 12 X . X O O O . . . . . . . . .(O). . . 12
 11 . X O . . . . . . . . . . . . . O . . 11
 10 . O . + . . . . . + . . . . X X X X . 10
  9 . . . . . . . . . . . . . O X O X . .  9
  8 . . . X . . . . . . . . . . O O O X .  8
  7 . . . . . . . . . . . O O . O X X . .  7
  6 . X . X . . . . . . O X O . X O X . .  6
  5 . . . O . . . X X X X X O . . O O . .  5
  4 . . . + . . O O O O X . X O O O X O .  4
  3 . . . O . . . . . . O . X . X X X X .  3
  2 . . . . . . . . . . . . . . . . . . .  2
  1 . . . . . . . . . . . . . . . . . . .  1
    A B C D E F G H J K L M N O P Q R S T

GoGuiで観戦

GoGui4を使えばGUI形式でも眺められます.

macOSなら下記コマンドでインストールできます.

brew tap homebrew/games
brew install go-gui

下記コマンドでGo Guiが立ち上がります.

gogui

image.png

References


  1. wangjinzhuo, pgd 

  2. Sensei's Library, Smart Game Format 

  3. bump, GNU GO 

  4. Go Gui 

13
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
15