Look at the game records of Go professional Go players

In wangjinzhuo / pgd [^ 1], about 260,000 professional game record data are stored in SGF format [^ 2].

What is SGF

It is an abbreviation for Smart Game Format (Smart Go Format) and is often used to save Go game records. (Rather, I've never seen anything other than Go ...) The following is an example of SGF data [^ 2], where KM represents Komi, B and W represent black and white, respectively, and the two letters in [] represent the position.

 (;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]))

Download game data

git clone https://github.com/wangjinzhuo/pgd.git #Dataset download
pip install -U sgf #Installation of sgf parser

Reading the game

You can read the game by writing as follows.

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

fpath = u"All/(Kaei 2 years)1849-10-8_None_Yuzo Ota 7th Dan_None_Honinbo Shusaku 6th Dan_None_B+4 eyes.sgf"
print(fpath)
game_tree = sgf.parse(open(fpath).read()).children[0]
node = game_tree.root
while node:
    print(node.properties)
    node = node.next

Execution result

All/(Kaei 2 years)1849-10-8_None_Yuzo Ota 7th Dan_None_Honinbo Shusaku 6th Dan_None_B+4 eyes.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']}

Watch the game with GNU GO

If you use GNU GO [^ 3], you can also display it on the board in CUI format. You can install it on macOS with the following command.

brew tap homebrew/games
brew install gnu-go

If you want to display up to the 100th move, you can display it by writing as follows.

$ gnugo --mode ascii -l "All/(Kaei 2 years)1849-10-8_None_Yuzo Ota 7th Dan_None_Honinbo Shusaku 6th Dan_None_B+4 eyes.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

Watch games with GoGui

If you use GoGui [^ 4], you can also view it in GUI format.

If you are using macOS, you can install it with the following command.

brew tap homebrew/games
brew install go-gui

Go Gui will start up with the following command.

gogui

image.png

References

Recommended Posts

Look at the game records of Go professional Go players
[Go] Take a look at io.Writer
Let's take a look at the feature map of YOLO v3
Summarize the titles of Hottentori at the end and look at the present on the Web
Python Basic Course (at the end of 15)
Reading comprehension of "The Go Memory Model"
Send Gmail at the end of the process [Python]
[At Coder] Solve the problem of binary search
At the time of python update on ubuntu
Remove specific strings at the end of python
I took a look at the contents of sklearn (scikit-learn) (1) ~ What about the implementation of CountVectorizer? ~