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手
   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:
開始日時:2018/03/17
開始日時:2004/04/01 21:46:07

終了日時

End date of the game, time can also be specified. The most common format is also yyyy/MM/dd HH:mm:ss.

Example:
終了日時:2021/09/10
終了日時:2012/12/21 12:12:21

棋戦

Name of the tournament where the game was played. Lishogi also uses this field for the type of the game.

Example:
棋戦:名人戦
棋戦:Casual Blitz game

場所

Location where the game occurred. Either real physical location or internet site/application.

Example:
場所:東京・将棋会館
場所:lishogi.org

持ち時間

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:
持ち時間:15分+60秒
持ち時間:15分
秒読み:60秒

戦型

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

2三
(24)

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

7八

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:
16 7二銀(71) ( 3:00/00:33:00)
1 7六歩(77) (00:7/)

Variations

先手: 後手: 後手の持駒:角 金四 銀二 桂三 香三 歩十七 +---------------------------+ | ・ ・ ・ ・ 飛 角 ・v玉 ・|一 | ・ ・ ・ ・ ・v銀 ・ ・ ・|二 | ・ ・ ・ ・ ・ ・ ・v桂 ・|三 | ・ ・ ・ ・ ・v銀 ・ 香 歩|四 | ・ ・ ・ ・ ・ ・ ・ ・ ・|五 | ・ ・ ・ ・ ・ ・ ・v飛 ・|六 | ・ ・ ・ ・ ・ ・ ・ ・ ・|七 | ・ ・ ・ ・ ・ ・ ・ ・ ・|八 | ・ ・ ・ ・ ・ ・ 玉 ・ ・|九 +---------------------------+ 先手の持駒:なし 手数----指手---------消費時間-- * Mate in 13. Created by Karolina Pro. 1 2三角成(41) 2 3一香打 3 3三桂打 4 同 銀(44) 5 同 馬(23) 6 2四飛(26) 7 3一飛成(51) 8 同 銀(42) 9 1二銀打 10 同 玉(21) 11 1三香打 12 2一玉(12) 13 1一香成(13) 変化:8手 8 3一玉(21) 9 3二銀打 変化:4手 4 3三銀(42) 5 同 馬(23) 6 2四飛(26) 7 3一飛成(51) 8 1二玉(21) 9 1三銀打 変化:6手 6 2二銀打 7 3二銀打 8 1二玉(21) 9 2二馬(33) 変化:2手 2 3一金打 3 2二馬(23)

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:
#KIF version=2.0 encoding=UTF-8
開始日時: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.

Reconnecting