Shogi Kifu to JSON Converter
Convert Shogi KIF, KI2, and CSA kifu notation files to structured JSON or JavaScript objects. Supports moves, variations, time, and headers.
About
Shogi game records (kifu) exist in three dominant text formats: KIF (the most common human-readable notation using full-width numerals and kanji piece names), KI2 (a condensed variant omitting origin squares and relying on disambiguation suffixes like 右, 左, 直), and CSA (a machine-oriented protocol using ASCII piece codes like FU, KA, HI with four-digit coordinate pairs). Incorrect parsing of these formats leads to corrupted move sequences, lost variation trees, and broken analysis pipelines. This tool performs real structural parsing of all three formats into a normalized JSON schema that preserves headers, board state, move coordinates, piece identifiers (integer-encoded: 1 - 14), time data, comments, and nested variation branches. It handles handicap games with custom initial positions, special termination markers (投了, 中断, 千日手), and the 同 (same-square) shorthand. The output conforms to the kifuParser schema by sandai. Limitations: KI2 disambiguation is resolved syntactically, not by board-state simulation, so ambiguous positions in non-standard KI2 may require manual verification.
Formulas
The parser converts shogi notation coordinates to zero-indexed array positions. For a 9×9 board represented as a flat array of 81 elements:
where col ∈ [1, 9] is the column number (right to left in traditional shogi notation, but stored left to right in the array) and row ∈ [1, 9] is the row number (top to bottom). In the output JSON, coordinates use 1-indexed arrays [col, row] matching the original kifuParser schema.
Piece integer encoding follows:
Negative integers represent white pieces on the initial board: sign = −1 for white (gote), +1 for black (sente). The turn boolean is TRUE for black (sente) and FALSE for white (gote). A from value of [0, 0] indicates a piece drop from hand.
Format auto-detection scoring: each line of input is tested against format-specific regexes. The format with the highest match count wins. Tie-breaking order: KIF → CSA → KI2.
Reference Data
| Piece (EN) | Kanji | CSA Code | Int ID | Promoted | Promoted Kanji | Promoted CSA | Promoted Int ID |
|---|---|---|---|---|---|---|---|
| Pawn | 歩 | FU | 1 | Tokin | と | TO | 9 |
| Lance | 香 | KY | 2 | Promoted Lance | 杏 | NY | 10 |
| Knight | 桂 | KE | 3 | Promoted Knight | 圭 | NK | 11 |
| Silver | 銀 | GI | 4 | Promoted Silver | 全 | NG | 12 |
| Gold | 金 | KI | 5 | - | - | - | - |
| Bishop | 角 | KA | 6 | Horse | 馬 | UM | 13 |
| Rook | 飛 | HI | 7 | Dragon | 龍 | RY | 14 |
| King | 玉/王 | OU | 8 | - | - | - | - |
| Format Identification Heuristics | |||||||
| KIF Format | Lines match ^\d+\s+[0-9一二三四五六七八九同] - full-width numerals, kanji pieces, origin in parentheses | ||||||
| KI2 Format | Move tokens prefixed with ▲ (black) or △ (white), no origin coordinates, disambiguation via kanji suffixes | ||||||
| CSA Format | Lines match ^[+-]\d{4}[A-Z]{2} - ASCII piece codes, four-digit coords, %-prefixed specials | ||||||
| Special Move Tokens | |||||||
| Resign | KIF: 投了 | CSA: %TORYO | |||||
| Interruption | KIF: 中断 | CSA: %CHUDAN | |||||
| Repetition | KIF: 千日手 | CSA: %SENNICHITE | |||||
| Impasse | KIF: 持将棋 | CSA: %JISHOGI | |||||
| Time Loss | KIF: 切れ負け | CSA: %TIME_UP | |||||
| Illegal Move | KIF: 反則勝ち/反則負け | CSA: %ILLEGAL_MOVE | |||||
| Coordinate Systems | |||||||
| KIF | Column: full-width 1 - 9, Row: kanji 一 - 九. Origin in half-width parens: (77) | ||||||
| KI2 | Same as KIF for destination. No origin. Disambiguation: 右(right), 左(left), 直(straight), 上(up), 寄(sideways), 引(back) | ||||||
| CSA | Four digits: first two = origin col+row, last two = dest col+row. 00 origin = drop from hand | ||||||