Forsyth-Edwards Notation - Chessprogramming Wiki

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] .

Contents

  • 1 FEN Syntax
    • 1.1 Piece Placement
    • 1.2 Side to move
    • 1.3 Castling ability
    • 1.4 En passant target square
    • 1.5 Halfmove Clock
    • 1.6 Fullmove counter
  • 2 Samples
  • 3 Chess960
    • 3.1 Shredder-FEN
    • 3.2 X-FEN
  • 4 See also
  • 5 Forum Posts
    • 5.1 1993 ...
    • 5.2 2000 ...
    • 5.3 2005 ...
    • 5.4 2010 ...
    • 5.5 2015 ...
    • 5.6 2020 ...
  • 6 External Links
  • 7 References
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
  • Extended Position Description (EPD)
  • Forsyth-Edwards Expanded Notation (FEEN)
  • Portable Game Notation (PGN)
  • BMI2 FEN Compression
Forum Posts

1993 ...

  • Revised PGN standard available by Steven Edwards, rgc, December 20, 1993 » Portable Game Notation
  • Full definition for FEN by Dann Corbit, CCC, May 27, 1999

2000 ...

  • File name extensions by Leen Ammeraal, CCC, November 14, 2000
  • Ten years later: revising EPD/FEN/PGN by Steven Edwards, CCC, September 09, 2003
  • Making positions in eps by Renze Steenhuisen, CCC, October 27, 2003 » Fen2eps

2005 ...

  • Why to use compatible X-FEN (in Chess960) by Reinhard Scharnagl, CCC, July 17, 2005
  • Chess960: X-FEN rules international by Reinhard Scharnagl, CCC, August 03, 2005
  • contradicting FEN and SMK-FEN by Reinhard Scharnagl, CCC, August 04, 2005
  • Chess960: Arena castle vs X-FEN castle by Matthias Gemuh, CCC, November 05, 2005
  • fen to fen functions by Uri Blass, CCC, May 21, 2007

2010 ...

  • where FEN is not consistent by Reinhard Scharnagl, CCC, January 06, 2010
  • FEN string by colin, CCC, January 30, 2011
  • No more pseudolegal en passant target foolishness by Steven Edwards, CCC, February 27, 2011
  • What's wrong with this EPD? by Jouni Uski, CCC, March 20, 2011
  • Question about Shredder FEN and X-FEN by Harm Geert Muller, CCC, April 22, 2012
  • Re: Causes for inconsistent benchmark signatures by Evert Glebbeek, CCC, March 27, 2013 » En passant
  • The maximum character length of a FEN string by Steven Edwards, CCC, August 24, 2013
  • Is 79 maximal? by Louis Zulli, CCC, July 29, 2014
  • PGN to FEN (with Evaluation)? by Steve Maughan, CCC, December 28, 2014 » Portable Game Notation, Python

2015 ...

  • Binary FEN by J. Wesley Cleveland, CCC, July 24, 2015
  • Any tool to convert FEN strings to diagrams? by Ted Wong, CCC, February 15, 2016
  • FEN - Flipper for Windows by Matthias Gemuh, CCC, May 17, 2017 » Color Flipping, EPD
  • 50 move counter in FEN and GUIs by Jouni Uski, CCC, November 12, 2019

2020 ...

  • FEN and 3rd repetition rule. No information? by Luis Babboni, CCC, April 03, 2020 » Repetitions
  • FEN compression by lucasart, CCC, March 17, 2021 » FEN Compression, NNUE Training
  • Required fields in Forsyth-Edwards Notation (FEN) by Niels Abildskov, CCC, April 02, 2022
External Links
  • Forsyth-Edwards Notation from Wikipedia
  • Chess Programming - Chess Board Implementation : A FEN parser by Thomas Petzke
  • FEN Database by Mathieu Pagé
  • Gilith - Chess Diagram Maker by Joe Leslie-Hurd
fen2img Chess Diagram Maker by Joe Leslie-Hurd
  • Chess Diagram Generator
  • GitHub - bagaturchess/ChessBoardScanner: Java based Chess Board Scanner, which converts 2D chess board image into a machine readable format a.k.a. Forsyth–Edwards Notation (FEN) by Krasimir Topchiyski
  • Chessforeva: 3D chess diagram from FEN » 3D Graphics Board
  • Fen2eps by Dirk Baechle [6]
References
  1. Standard: Portable Game Notation Specification and Implementation Guide 16.1: FEN by Steven Edwards
  2. Re: Arasan test suite update by Steven Edwards, CCC, September 19, 2008
  3. where FEN is not consistent by Reinhard Scharnagl, CCC, January 06, 2010
  4. No more pseudolegal en passant target foolishness by Steven Edwards, CCC, February 27, 2011
  5. Why to use compatible X-FEN (in Chess960) by Reinhard Scharnagl, CCC, July 17, 2005
  6. Encapsulated PostScript from Wikipedia

Up one Level

Từ khóa » Chuỗi Fen