Forsyth-Edwards Notation

From Chessprogramming wiki
Jump to: navigation, search

Home * Chess * Position * Forsyth-Edwards Notation

Forsyth-Edwards Notation (FEN) describes a Chess Position. It is an one-line ASCII-string. FEN is based on a system created by Scotsman David Forsyth in the 19th century. Steven Edwards specified the FEN standard for computer chess applications as part of the Portable Game Notation [1] .

FEN Syntax

One FEN string or record consists of six fields separated by a space character. The first four fields of the FEN specification are the same as the first four fields of the EPD specification.

Terminal and nonterminal symbols of a variant of BNF below are embedded in ' ' resp. < >.

<FEN> ::=  <Piece Placement>
       ' ' <Side to move>
       ' ' <Castling ability>
       ' ' <En passant target square>
       ' ' <Halfmove clock>
       ' ' <Fullmove counter>

Piece Placement

The Piece Placement is determined rank by rank in big-endian order, that is starting at the 8th rank down to the first rank. Each rank is separated by the terminal symbol '/' (slash). One rank, scans piece placement in little-endian file-order from the A to H.

A decimal digit counts consecutive empty squares, the pieces are identified by a single letter from standard English names for chess pieces as used in the Algebraic Chess Notation. Uppercase letters are for white pieces, lowercase letters for black pieces.

<Piece Placement> ::= <rank8>'/'<rank7>'/'<rank6>'/'<rank5>'/'<rank4>'/'<rank3>'/'<rank2>'/'<rank1>
<ranki>       ::= [<digit17>]<piece> {[<digit17>]<piece>} [<digit17>] | '8'
<piece>       ::= <white Piece> | <black Piece>
<digit17>     ::= '1' | '2' | '3' | '4' | '5' | '6' | '7'
<white Piece> ::= 'P' | 'N' | 'B' | 'R' | 'Q' | 'K'
<black Piece> ::= 'p' | 'n' | 'b' | 'r' | 'q' | 'k'

Side to move

Side to move is one lowercase letter for either White ('w') or Black ('b').

<Side to move> ::= {'w' | 'b'}

Castling ability

If neither side can castle, the symbol '-' is used, otherwise each of four individual castling rights for king and queen castling for both sides are indicated by a sequence of one to four letters.

<Castling ability> ::= '-' | ['K'] ['Q'] ['k'] ['q'] (1..4)

En passant target square

The en passant target square is specified after a double push of a pawn, no matter whether an en passant capture is really possible or not [2] [3] [4] . Other moves than double pawn pushes imply the symbol '-' for this FEN field.

<En passant target square> ::= '-' | <epsquare>
<epsquare>   ::= <fileLetter> <eprank>
<fileLetter> ::= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h'
<eprank>     ::= '3' | '6'

Halfmove Clock

The halfmove clock specifies a decimal number of half moves with respect to the 50 move draw rule. It is reset to zero after a capture or a pawn move and incremented otherwise.

<Halfmove Clock> ::= <digit> {<digit>}
<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'

Fullmove counter

The number of the full moves in a game. It starts at 1, and is incremented after each Black's move.

<Fullmove counter> ::= <digit19> {<digit>}
<digit19> ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<digit>   ::= '0' | <digit19>

Samples

FEN strings of Starting Position and after 1.e4 c5 2.Nf3:

    
    
    
    
    
    
    
    


        
        
        
        


♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
        
        
        
        
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
    
    
    
    
    
    
    
    


        
        
       
        
 

♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
        
        
    ♙   
        
♙♙♙♙ ♙♙♙
♖♘♗♕♔♗♘♖
1.e4
rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1
    
    
    
    
    
    
    
    

 
        
       
       
        
 

♜♞♝♛♚♝♞♜
♟♟ ♟♟♟♟♟
        
  ♟     
    ♙   
        
♙♙♙♙ ♙♙♙
♖♘♗♕♔♗♘♖
1.e4 c5
rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2
    
    
    
    
    
    
    
    

 
        
       
       
       
 
 
♜♞♝♛♚♝♞♜
♟♟ ♟♟♟♟♟
        
  ♟     
    ♙   
     ♘  
♙♙♙♙ ♙♙♙
♖♘♗♕♔♗ ♖
1.e4 c5 2.Nf3
rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2 

Chess960

Shredder-FEN

Shredder-FEN or SMK-FEN is an extension of FEN covering Chess960, introduced by Shredder author Stefan Meyer-Kahlen (SMK) in 2005. Shredder-FEN uses different castling right characters, that is instead of KQkq, upper case and lower case file characters of the affected rooks for white and black castling rights, and became a de facto standard supported by most GUIs and protocols.

X-FEN

The earlier X-FEN extension was introduced by Reinhard Scharnagl in 2003, and covers not only Chess960 but also 10x8 variants. Its author dogmatically claimed upward compatibility with standard chess [5], still using the KQkq castling right characters for all Chess960 positions. Further, X-FEN introduced a changed en passant target square semantic, which is only specified after a double pawn push was made beside an opponent pawn that might capture en passant if legal, that is not leaving its king in check.

See also

Forum Posts

1993 ...

2000 ...

2005 ...

2010 ...

2015 ...

2020 ...

External Links

fen2img Chess Diagram Maker by Joe Leslie-Hurd

References

Up one Level