Shogi Kifu Game Record to PGN
(more-or-less)
This page is about my effort to
translate .kif or .ki2
format Shogi game records to western style chess notation. The Python
source program described in the following paragraphs may be examined or
downloaded here.
If you use or improve it please let me know.
Background: When Bobby Fischer won the world chess championship in 1972, the way his moves were recorded was different from the way those same moves would be recorded today. If his first move in a game was to push the pawn in front of the king two squares forward it would have been recorded as P-K4, spoken “pawn to king 4.” This move recording system was called “descriptive notation.”

Since the advent of chess-playing computers, or maybe before then, an alternative notation system was devised in which board squares are labeled algebraically, files ‘a’ to ‘h’ from left-to-right, and ranks 1 to 8 starting at the white side of the board. The move P-K4 is the same as moving the pawn from square e2 to square e4 in algebraic notation, which does not rely on ‘king side’ or ‘queen side’ file qualifiers. The move P-K4 could be written e2-e4 or Pe4 or simply e4. This way of denoting moves is used in ‘Portable Game Notation’ or PGN game records.

A few years ago I read a fascinating book called Kingdom of Characters by Jing Tsu of Yale University. Before reading this book I had never thought about the tremendous advantage that alphabet-based written languages possess for adapting to computers, or for that matter to the printing press! Any word or phrase or sentence in the English language can be expressed as a string of alphabetic characters and punctuation marks, each consuming a single byte of storage (or a single block of lead). The story of non-alphabetic languages is too long and complex to summarize here, but if you’re curious about how it became possible to make a typewriter for Chinese, I recommend Kingdom of Characters.

The problem: Japanese chess (Shogi) games have been recorded in writing for several centuries, although Internet Shogi game databases are apparently not as voluminous as international chess databases, which now contain millions of games. However, both the Japanese written language and the way in which Shogi games are recorded have evolved over time, and in particular, they have adapted to the computer age. For example, older handwritten Shogi game records were typically recorded right-to-left. Also, since Japanese is not an alphabetic language, both ranks and files of a Shogi board are denoted by numerals 1 - 9. Skipping countless details, a standard called ‘kifu’ has evolved for recording Shogi games, and for use in computer game play.

The rest of this story will refer to the example game shown above in its original kifu-recorded form. This game was played and saved using a computer application called ShogiHome. Both the preamble and list of plays use a mixture of Kanji and English characters. Moreover, the order of play proceeds left-to-right across the first row, then down one row, and so forth. Black plays first in Shogi. Filled triangles ▲ indicate black plays and empty triangles △ denote white plays. The black side is called ‘Sente’ and the white side ‘Gote’. It is common practice to number each ply in a Shogi game (equivalent to a half-move in international chess). However, plies are not numbered in the illustrated example.
Translation: The first two characters following the triangle symbols (reading left-to-right) generally denote the play’s target square. There are exceptions, such as sometimes when a piece is captured (e.g. third row, second column). The next character to the right of the target square or other play indication is the name of the piece being played. Although the full piece name is two characters, only the first is recorded. It may also be necessary to indicate whether a piece is being promoted, or was previously promoted, or in some cases to resolve an ambiguity about the play. Just as in international chess, it is possible that two pieces of the same type may target the same square, in which case it is necessary to specify which one made the play.

As was noted in a previous paragraph both ranks and files are numbered. Strange as it may seem, in kifu notation files (columns) are denoted in the familiar Arabic numerals, while ranks (rows) are labeled with their corresponding Kanji numerals (illustration above). In most cases the kifu way of recording a square’s coordinates can be translated to the PGN equivalent in just a few steps. I will illustrate with the first play in the example game ▲2六歩.
The character 六 is the numeral 6, so 2六 indicates that the file is 2 and the rank is 6. However, everything is upside down and mirror-reversed with respect to western style. File number 2 from the right hand side of the board would be number 8 from the left. Similarly rank number 6 counting from the top of the board corresponds to rank number 4 from the bottom (western style). Finally, PGN-style file labels are English alphabet letters. The 8th letter of the alphabet is ‘h’ so file 8 is designated as ‘h’, and since files are named first in PGN, the complete square designation 2六 translates to ‘h4’.

This account omits a number of messy details. Computer encodings of the Japanese language also appear to have evolved over the last few decades. Therefore, different documents, for example game records from different eras, may have been encoded differently. Some Shogi games are recorded natively in a PGN-like format. However, the small project described on this page was about translation, and the illustration above shows my Python program’s translation of the example kifu game record, using a standard character encoding called ‘Shift_JIS’ to read and interpret the game record.
Kifu is sparse. Probably PGN is also so, especially when shortcuts are used. For example the translated Shogi play 15 Pb4 was a capture, which could be written as Pxb4 in PGN. However, without including the ‘x’ symbol to emphasize the capture, the play notation is unambiguous. Similarly 20 Bb3 was a drop, but only a dropped bishop could target the b3 square for that play, so the drop was also unambiguous, and not explicitly notated. The last play 24 Sg1, also a drop, was checkmate. As far as I know, there is no symbol in kifu for checkmate. A win is a win no matter whether by checkmate or resignation or any other Shogi rule.
The translation exercise described in these paragraphs has been tested with .kif and .ki2 format game records. The Python sketch (program) that produced the example translation is linked from the first paragraph on this page. It is approximately 150 lines of code. To exercise the program, assuming Python is installed, enter: python kif2pgn.py -file="path to kifu game record file" from a Windows/DOS/PowerShell command prompt.
Notes: This page was originally composed in MS Word and exported from there in HTML format, then edited. The Kingdom of Characters book cover image came from an advertisement.
Project descriptions are intended for entertainment only. The author makes no claim as to the accuracy or completeness of the information presented. In no event will the author be liable for any damages, lost effort, inability to carry out a similar project, or to reproduce a claimed result, or anything else relating to a decision to use the information on this page.