Kif
Kif is probably the most popular file format used to represent not only full shogi games, but also studies of games, tsume problems and other types of puzzles.
The aim of this post is to explain this format, in case you are not fully familiar with it. If you spot any inaccuracies, typos or you feel that something isn't explained properly, please submit an issue on github. First let's take a look how a KIF file looks.
先手:
後手:
  1  7六歩(77) ( 0:00/00:00:00)
  2  8四歩(83) ( 0:00/00:00:00)
  3  5六歩(57) ( 0:00/00:00:00)
  4  5四歩(53) ( 0:00/00:00:00)
  5  5八飛(28) ( 0:00/00:00:00)
  6  4二金(41) ( 0:00/00:00:00)
  7  5五歩(56) ( 0:00/00:00:00)
  8  同 歩(54) ( 0:00/00:00:00)
  9  同 角(88) ( 0:00/00:00:00)
  10  8五歩(84) ( 0:00/00:00:00)
  11  7三角成(55) ( 0:00/00:00:00)
  8   5二飛(82) ( 0:00/00:00:00)
Header
Header contains general information about the game or study. Every tag starts at a new line, the tag name and tag value is separated by ':'.
While everyone can use their own tags, to convey whatever information they want, there are some tags, that a lot of kif files share. So let's look at the most important tags here.
先手
Sente's (black's) player name. This can include titles, ranks, etc. 下手 should be used in handicap games. This field is often required, even if the name of the player is unknown or not relevant (for example in puzzles).
Example:
後手
Gote's (white's) player name. This can include titles, ranks, etc. 上手 should be used in handicap games. This field is often required, even if the name of the player is unknown or not relevant (for example in puzzles).
Example:
手合割
Type of handicap. This specifies initial position of the game, for standard starting position 「平手」 is used. This doesn't always mean the moves provided in the kif file necessarily start at this position, only that the game started at that position (for example in studies of games we might include only the relevant part of the game, but still keeping this tag to know how the game started), if that's the case, specific board setup is provided - next field. For list of handicaps see Editor.
Example:
Board setup
Games from non-standard positions, tsume problems, etc. need to specify the initial board position. Works very similarly to SFEN. We display the board from sente's view. Gote's pieces are preceded by 'v'. For promoted pieces we use single kanji variants. Pieces in hand are shown above and below the board, if player has no pieces in hand , we write「なし」. If it's gote's turn 後手番 is noted on a new line.
Example:
9 8 7 6 5 4 3 2 1
+---------------------------+
| ・ ・ ・v桂 ・ ・ ・ ・ ・|一
|v玉 角v歩 馬 ・ ・ ・ ・ ・|二
| ・ ・ ・ ・ ・ ・ ・ ・ ・|三
| 桂 ・ ・v歩 ・ ・ ・ ・ ・|四
|vとv桂 ・ ・v歩 ・ ・ ・ ・|五
| ・ ・ 飛 ・v全 ・ ・ ・ ・|六
|v歩 桂 ・ ・ ・ ・ ・ ・ ・|七
| ・ 香 ・ ・ ・ ・ ・ ・ ・|八
| ・v銀 ・ ・ 龍 ・ ・ ・ ・|九
+---------------------------+
先手の持駒:なし
開始日時
Start date of the game, time can also be specified. The most common format is yyyy/MM/dd HH:mm:ss.
Example:
終了日時
End date of the game, time can also be specified. The most common format is also yyyy/MM/dd HH:mm:ss.
Example:
棋戦
Name of the tournament where the game was played. Lishogi also uses this field for the type of the game.
Example:
場所
Location where the game occurred. Either real physical location or internet site/application.
Example:
持ち時間
Initial time of the game. Byoyomi might be included in this field or additional field 「秒読み」 is included if necessary. First example means the same thing as the last two lines together.
Example:
戦型
Game opening that was played.
Example:
For tsume puzzles additional set of tags is commonly used - author of the puzzle, where it was published, etc. Take a look here, if you are interested.
Moves
Standard move
Destination
File is represented by full-width number and rank by Japanese numeral. If the destination is the same as the last one 「同 」 is used (note the space after 同). It's essentially the same as in standard Japanese notation.
Piece
If you are familiar with Japanese move notation, this shouldn't surprise you, because it's the same.
Promotion
If the piece is being promoted 「成」 is noted. If a non-promotion by choice occurs, 「不成」 is not noted.
Origin
Origin square is always noted by two half-width numbers in parentheses.
Drop
Drop is very similar, with a small exception - for obvious reasons we drop the origin string and instead 「打」is noted.
Termination moves
The reason for the game's termination is also recorded as a move.
中断
Game was aborted.
投了
Resignation. The player whose turn it was, is the one who resigned. Time that it took the player to resign can also be noted.
千日手
Four-fold repetition.
詰み
Checkmate or stalemate. The player whose turn it was, is the one who is checkmated.
切れ負け
Losing on time. The player whose turn it was, is the one who ran out of time. Some sites use "Time-up" instead.
反則勝ち
Indicates that the immediately preceding move was illegal.
反則負け
Indicates that the player whose turn this was supposed to be somehow lost by illegality.
入玉勝ち
Indicates that the player whose it was, declared win by entering king.
Time expended
On the same line as the move, times might be recorded.
The times are recorded within parentheses separated by "/". The first number is the time spent on that one move in [minute:seconds]. The second number is that player's total time expended thus far in the game in [hours:minutes:seconds].
Either no time, time spent on this move or both times might be recorded.
Example:
Variations
Each variations starts with 「変化:」 after which is the number of the move we are branching out of. We list the variations in decreasing order of the move number, if the move number is greater than the previous variation number, it means that the previous variation is a parent to this variation - you can see that with variation 6 and variation 4.
Other
Everything after '#' will be ignored by parsers. These comment usually provide some information about when was the file created or what encoding was used.
Example:
開始日時:2017/04/02
持ち時間:5分+30秒
手数----指手---------消費時間-- # Not mandatory
...
To comment on moves, start the line with '*', everything after that on the same line is a comment. You can use multiple comments this way.
Example:
1 7六歩(77) ( 0:00/00:00:00)
*定刻の9時、対局開始。両対局者が一礼し、しばらくして木村が盤上に手を伸ばした。
*
*【対局開始前の様子】
*http://kifulog.shogi.or.jp/oui/2016/09/post-1bd0.html
2 8四歩(83) ( 0:00/00:00:00)
*羽生は木村の着手を見ると、目を閉じて上を向き、やがてゆっくりと舞うような手つきで歩を前に進めた。
3 2六歩(27) ( 3:00/00:03:00)
...
Final comments
Many thanks to the author of this text and Marken-Foo for translating it.
If you find any mistakes in this text or want to add some additional information, please submit an issue on github.