Upgrade to Chess.com Premium!

How do I create a FEN string?


  • 3 years ago · Quote · #1

    homernh

    I'm trying to do a diagram for a TT problem with no source game.  I don't mind dragging the pieces to create the initial setup, but I'd like to translate that into a FEN string so I won't have to do it all over again if somethings goes wrong or I want to change something later.  Any clues?

  • 3 years ago · Quote · #2

    unexceptional

    If you know the position, why not just write the FEN yourself? That's what it was made for. Am I missing something?

  • 3 years ago · Quote · #3

    homernh

    I haven't tried that... but there must be a way on chess.com to translate the postion into the string, right?

  • 3 years ago · Quote · #4

    unexceptional

    I don't know if you can do it on chess.com, but a freeware gui like Tarrasch (www.triplehappy.com) will do it from a position. Really, the quickest way would be to do it in your head and type it: http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation

  • 3 years ago · Quote · #5

    homernh

    Thanks, Ian, I tried making my own FEN string and it turned out okay.

    1r2r2k/1p1n3R/p1qp2pB/6Pn/P1Pp/3B4/1P2PQ1K/5R b - - 0 1

    I always looked at the long string of numbers and assumed it was something like a quarterback rating that isn't easily deciphered.  But the wikipedia article walked me through it well enough. 

    A general question: never having done this before, I'm a little bit bothered by what seem to be 'optional' numbers for the ending spaces at the end of each rank. Shouldn't there be just one 'right' FEN string for a board postion?  If I understand correctly, my postion can be described as any of the following:

    1r2r2k/1p1n3R/p1qp2pB/6Pn/P1Pp/3B4/1P2PQ1K/5R2 b - - 0 1

    1r2r2k/1p1n3R/p1qp2pB/6Pn/P1Pp/3B/1P2PQ1K/5R2 b - - 0 1

    1r2r2k/1p1n3R/p1qp2pB/6Pn/P1Pp/3B4/1P2PQ1K/5R b - - 0 1

    1r2r2k/1p1n3R/p1qp2pB/6Pn/P1Pp/3B/1P2PQ1K/5R b - - 0 1

    If the ending spaces were required for each line, you wouldn't even need the '/' marks.  You'd just have a bunch of numbers and letters that added up to 64, right?  That would save you 7 characters in the string... and if you allowed the spaces to go from one line to the next (the opening position has 32 consectutive spaces in it, for example) you could shorten it even more, right? 

    Here's the TT problem with the completed diagram, if anyone wants to see it. 

    http://www.chess.com/tactics/server.html?id=781

  • 3 years ago · Quote · #6

    EscherehcsE

    homernh wrote:
    A general question: never having done this before, I'm a little bit bothered by what seem to be 'optional' numbers for the ending spaces at the end of each rank.

    I don't think these numbers are optional. Why do you think they're optional?

    If you put one of these shortened FENs into Tarrasch, it's smart enough to add back the "optional" numbers. But these shortened FENs will break Arena. Shredder, ChessPad, and Winboard are also smart enough to accept the shortened FENs, but Scid flags them as invalid.

  • 3 years ago · Quote · #7

    homernh

    Again, never having done this before, I thought they were optional because I left some out, but apparently chess.com is smart enough to add them back in.

    So, if they aren't optional, the '/' marks don't really add any information to the string, right?  (Other than make it easier for humans to read.) 

    rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 

    is the starting position, but

    rnbqkbnrpppppppp8888PPPPPPPPRNBQKBNR w KQkq - 0 1

    still conveys the same info about all 64 squares.  And it seems to me that

    rnbqkbnrpppppppp32PPPPPPPPRNBQKBNR w KQkq - 0 1

    does too.  Right?

  • 3 years ago · Quote · #8

    HGMuller

    I think that is the main idea: Human readability. It is also helpful when you don't know how wide the board is, e.g.

    rheakaehr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RHEAKAEHR w 0 1

    But it is not possible in general anyway to deduce the meaning of a FEN without knowing what the variant is.

  • 3 years ago · Quote · #9

    EscherehcsE

    homernh wrote:

    Again, never having done this before, I thought they were optional because I left some out, but apparently chess.com is smart enough to add them back in.

    So, if they aren't optional, the '/' marks don't really add any information to the string, right?  (Other than make it easier for humans to read.) 

    rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

    is the starting position, but

    rnbqkbnrpppppppp8888PPPPPPPPRNBQKBNR w KQkq - 0 1

    still conveys the same info about all 64 squares.  And it seems to me that

    rnbqkbnrpppppppp32PPPPPPPPRNBQKBNR w KQkq - 0 1

    does too.  Right?


    The slashes are probably mostly for the human's benefit (readability), but I'd guess that they're also useful to the programs as a second check. For example, if slashes weren't part of the specification, I doubt that any of the programs would be able to add back the missing "optional" blanks. Concerning your last FEN, the program would have a hard time deciding whether the 32 was thirty-two or a three and a two. It would have to parse the entire board position before it could understand your intent. Why make it that complicated when it doesn't have to be?

    Argh, beaten by HGM. And I didn't consider the variant issue. Smile

  • 3 years ago · Quote · #10

    homernh

    HGMuller wrote:

    I think that is the main idea: Human readability. It is also helpful when you don't know how wide the board is, e.g.

    rheakaehr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RHEAKAEHR w 0 1


    Helpful, yes, but is it required?  Remove all the backslashes from your string, and you still have 32 letters and numbers that add up to 58 - a total of 90 squares.  That's a 9x10 board.  (I still don't know what variation that is, but I assume whoever plays on such a board will recognize it.)

  • 3 years ago · Quote · #11

    homernh

    EscherehcsE wrote:

    The slashes are probably mostly for the human's benefit (readability), but I'd guess that they're also useful to the programs as a second check. For example, if slashes weren't part of the specification, I doubt that any of the programs would be able to add back the missing "optional" blanks.

    Concerning your last FEN, the program would have a hard time deciding whether the 32 was thirty-two or a three and a two. It would have to parse the entire board position before it could understand your intent. Why make it that complicated when it doesn't have to be?


    Right, I agree either some numbers can be optional or the backslashes can be removed - but not both. 

    I did wonder about potential problem with 2 digit numbers.  Since HGM brought it up, the varient issue has to deal with this, right?  Aren't there 10x10 and 12x12 boards? 

    But I don't think the program would have a problem figuring out if '32' was a 3 and a 2 or a 32.  First, beside the obvious oversight of recording there were 3 spaces followed by 2 spaces instead of just saying 5 spaces, the program would be doing a simple check anyway to check the validity of the string - numbers plus letters should equal 64 (for an 8x8 board).  32 letters plus 3 plus 2 = 37 = invalid string.  32 letters + 32 = 64 = valid string. 

    Chess.com does a similar thing and requires that there be 7 '/' in a FEN string, even if you don't want any pieces at the bottom of the board. 

    I have no dog in this, I don't care one way or another (and I enjoyed learning about FEN - I always though the first two letters in the starting string were 'm', not 'rn') but I was looking for some confirmation that the backslashes are purposely inefficient for human benefit. 

    Or is this a conspiracy by backslash key manufacturers?  Think about it...

  • 3 years ago · Quote · #12

    EscherehcsE

    homernh wrote

    Or is this a conspiracy by backslash key manufacturers?  Think about it...


    I/don't/know/what/you're/talking/about./There/can't/be/any/conspiracy./It/makes/perfect/sense/to/me.

  • 3 years ago · Quote · #13

    HGMuller

    FEN is a format designed for Humans, and predates computers by a long time. So robustness against errors is an important requirement, and the slashes definitely help to detect errors. It would have been possible to encode the board as raster scan, combining empty squares on different ranks (i.e. write 32 in stead of /8/8/8/8/). That would in general be more compact, and even lower the number of required digits as well as getting rid of redundant slashes. But that is not FEN.

  • 2 years ago · Quote · #14

    nthompson

    thanks, homernh for starting a truly interesting and informative thread.  Ah the power of a good, honest question!  N

  • 2 years ago · Quote · #15

    P-k3

    When using fen how does one use numbers instead of pieces. I want to show the number of moves to a point on the board. How is this done?

  • 2 years ago · Quote · #16

    qixel

    P-k3 wrote:

    When using fen how does one use numbers instead of pieces. I want to show the number of moves to a point on the board. How is this done?

    I don't know if I totally understand your question, but the final number in the FEN string indicates the full move number of the position.

  • 2 years ago · Quote · #17

    stephen_33

    Some great advice above but nobody's actually answered the OP's question: Once you've dragged all the pieces to their proper places on the board in Position Setup mode (Analysis Board-Editor) then click on the Copy FEN To Clipboard button & you can copy & paste the FEN string anywhere, such as a text-editor like Notepad.

    Then it's pretty easy to play around with it as you want. For example, set the final number (this gives the 'next move' value-usually set to 1) in the FEN string to any value to indicate the move at which you want to begin in a diagram.

    If you want to know more then Wiki' is really good - post #4 has the link.

  • 2 years ago · Quote · #18

    MrEdCollins

    The absolute easiest way to create a FEN string is with a chess GUI. 

    Most all of the better GUIs have a "position setup" feature.  With this feature you can setup any board position.  Once the board is setup to your desired position, the GUI will almost surely have a "Copy FEN to Clipboard" button or shortcut.

    That's it.  You've just created a FEN string and can now copy it form your Windows clipboard to another program, a text editor, etc.

    The actual steps to go into each GUIs position setup mode will vary, depending upon what chess GUI you are using.

    Yes, you can use a text editor to create your FEN string, but that takes longer and is prone to error.   But if you don't HAVE a chess GUI (?) then I suppose it's the only way.

  • 2 years ago · Quote · #19

    P-k3

    is there a way to number all 64 squares?  So all squares have a number on them

  • 2 years ago · Quote · #20

    stephen_33

    P-k3 wrote:

    is there a way to number all 64 squares?  So all squares have a number on them

    If you mean to identify any square, doesn't algebraic notation do that already ?


Back to Top

Post your reply: