How do I create a FEN string?

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?

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.

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.

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?

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

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

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.

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.

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.

Help us finish translating:

We are working hard to make Chess.com available in over 70 languages. Check back over the year as we develop the technology to add more, and we will try our best to notify you when your language is ready for translating!