My favorites | Sign in
Project Logo
                
Search
for
Updated Jul 03, 2008 by fat.bold.cyclop
Labels: shogi, SFEN, software, standard
sfen_start  
SFEN_Spec: Shogi Forsyth-Edwards Notation specification.
 version 0.0.1
 2007.02.05
 by Fat Bold Cyclop

Introduction

SFEN stands for 'Shogi Forsyth-Edwards Notation'.

This specification is an attempt to establish a standard for board position representation for Shogi game in shogi software. It is intended for data interchange among Shogi programs, for position database programs and for problem test suites storage.

SFEN is an open standard. It is heavily based on Forsyth-Edwards Notation (FEN) developed for chess.

SFEN building blocks

A single SFEN record uses one text line of variable length composed of four data fields describing the current position. The last field (move count) is optional, others are mandatory. A text file composed exclusively of SFEN data records should have a file name with the suffix '.sfen'.

From left to right starting at the beginning of the record, these are the piece placement, the active color, the pieces in hand and move number – separated by single space character. These can all fit on a single text line in an easily read format. The length of an SFEN position description varies somewhat according to the position.

Depending on the host operating system, the external representation of SFEN records will include one or more bytes to indicate the end of a line. Each of the four SFEN data fields are composed only of non-blank printing ASCII characters. Adjacent data fields are separated by a single ASCII space character.

The following table is quasi-BNF description of SFEN.

SFEN_file	::=	( SFEN_record <EOL> )+
SFEN_record	::=	board <SPACE> side_on_move <SPACE> hand (<SPACE> move_number)?
board		::=	row <ROW_SEPARATOR> row <ROW_SEPARATOR> row <ROW_SEPARATOR> row <ROW_SEPARATOR> row <ROW_SEPARATOR> row <ROW_SEPARATOR> row <ROW_SEPARATOR> row <ROW_SEPARATOR> row

hand		::=	<NO_INFORMATION>
		|	( ( "R" | "B" | "G" | "S" | "N" | "L" | "P" | "r" | "b" | "g" | "s" | "n" | "l" | "p" )
			| ( integer ( "R" | "B" | "G" | "S" | "N" | "L" | "P" | "r" | "b" | "g" | "s" | "n" | "l" | "p" ) ) )+
side_on_move	::=	"B"| "W"
move_number     ::=     integer
row		::=	( integer |
			  ( ( <PROMOTION> )? "K" | "R" | "B" | "G" | "S" | "N" | "L" | "P" | "k" | "r" | "b" | "g" | "s" | "n" | "l" | "p" )
			)+
integer		::=	<["1"-"9"]> ( <["0"-"9"]> )?

<SPACE>		::=	' '
<NO_INFORMATION>::=	'-'
<PROMOTION>	::=	'+'
<EOL>		:=	"\n" | "\r"("\n")?

the grammar is used in actual javacc-based parser of SFEN files; to be polished later

The next sections contain more human-like description of the specification.

Piece placement data

The first field represents the placement of the pieces on the board (board field in the formal specification). The board contents are specified starting with the first – the top-most – rank ('a') and ending with the ninth rank ('i'). For each rank, the squares are specified from file 9 to file 1 (left-most to right-most).

''Diagrams generated with Web Diagram Generator: http://wormz.free.fr/kifugen/''

Black pieces are identified by uppercase letters, white pieces use lowercase letters. Unpromoted pieces are described with letters 'PLNSGK' ('plnsgk' for white). Promoted pieces are prefixed with plus char ('+').

English name Japanese name FEN Code for blackFEN Code for whiteKanji
King Kk
Rook Rr
Promoted rook ("Dragon") +R+r
Bishop Bb
Promoted bishop ("Horse") +B+b
Gold general ("Gold") Gg
Silver general ("Silver") Ss
Promoted silver +S+s
Knight Nn
Promoted knight +N+n
Lance Ll
Promoted lance +L+l
Pawn Pp
Promoted pawn ("tokin") +P+p

Empty squares are represented by the digits one through nine. The digit used represents the count of contiguous empty squares along a rank. The contents of all nine squares on each rank must be specified. The count of piece letters plus the sum of the vacant square counts must always equal nine. The solidus character '/' (forward slash) is used to separate data of adjacent ranks. There is no leading or trailing solidus in the piece placement data; hence there are exactly eight of solidus characters in the placement field. According to the definition, the piece placement data for the initial board setup is:

lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL

Active color

The second field represents the active color (side_on_move field in the formal specification). A upper case 'W' is used if White is to move; a upper case 'B' is used if Black is the active player.

According to the definition, the piece placement and active color data for the initial board setup is:

lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL B

Pieces in hand

The third field represents pieces in hand (hand field in the formal specification). If no information is provided, the minus sign (‘-‘) is used. Therefore, the piece placement, active color and pieces in hand data for the initial board setup with no player holding pieces in hand is:

lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL B -

If the information is available, the following convention is used:

According to the definition above and having the following tsume:

the piece placement, active color, pieces in hand is:

7r1/6B1p/6Bsk/9/7P1/9/9/9/9 B 2S

Move number

move_number represents the move number (ply) associated with the position. It is always positive integer value of the move number. The value of the move number for the starting array is one -- black move number from starting position is 1. After Black's move, White's move number is 2. The next Black's move number 3, etc.

This field is optional.

SFEN examples

In this section, few examples of SFEN data are given, along with their diagram representation.

7kl/9/6+r1+B/6+B2/9/9/9/9/9 B G

8l/7b1/8k/6+B2/7Pg/9/9/9/9 B R

7r1/6B1p/6Bsk/9/7P1/9/9/9/9 B 2SB

Other works

%%commentbox DRAFT %%.


Sign in to add a comment
Hosted by Google Code