Answers.Body: <h1>Let's start at the beginning</h1>
  <p>To understand X-FEN for castling in Chess960, it helps if you first understand castling in Chess960. Castling rules are slightly different in Chess960, hence there comes a need for X-FEN. I believe it's the major source for your confusion.</p>
  <p><strong>Minor Note 1</strong> X-FEN is used not just for Chess960 but for many other variants as well (Capablanca chess, Janus chess, Chess480, etc.)</p>
  <h2>Castling in Chess960</h2>
  <p>Castling in chess960 is done on two sides: <strong>the a-side and the h-side</strong>, analogous to queenside and kingside castling respectively. The final positions after castling are the same in Chess960 and in standard chess.</p>
  <p>The terms a-side and h-side are used as the initial board configuration is randomized, and what is <em>queenside</em> in normal chess needn't be so in Chess960 (the same applies for kingside.).</p>
  <h2>Why FEN is insufficient for Chess960</h2>
  <p>FEN is sufficient for standard chess, as there are only <em>two initial squares for the rooks, on the a-file and the h-file</em>.If a rook from the kingside somehow gets to say, the c-file, there is no question of allowing queenside castling with it as it isn't on the right square. (More on this in an example.)</p>
  <p>In chess960, the rooks have <em>many</em> possible initial squares. In the course of a game, both the rooks could end up on the same side of the king. Now, if FEN is used, there is no way of clearly knowing which rook has the castling rights (without knowing the initial position) as either could be occupying the <em>legal</em> square for castling. As a matter of fact, X-FEN assumes by default the <strong>outermost rook in such cases to have the castling rights,</strong> but that needn't be the case always.</p>
  <h2>An example to make my point clear</h2>
  <p><a href="https://i.sstatic.net/r5Cwh.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/r5Cwh.jpg" alt="A situation involving X-FEN" /></a></p>
  <h3>Standard Chess</h3>
  <p>If the above position occurred in a standard chess game, the FEN would simply be</p>
  <blockquote>
  <p>rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Kq - 4 11</p>
  </blockquote>
  <p>This is because White can castle legally on the kingside, with the rook on the h-file. The rook on the g-file would play no role in castling, simply because that isn't on the <em>legal square for kingside castling</em>.</p>
  <p>Likewise, Black can castle only on the queenside, hence the FEN has a <strong>q</strong> for the castling rights of Black. The rook on g8 is irrelevant.</p>
  <p><strong>Minor Note 2</strong> Precise readers might point out that the number of moves and half-moves required to arrive at the position shown, in a normal chess game, might not tally with the values given in the FEN. That is quite possibly true, but I stuck to the value given for the Chess960 game (for the same position) on Wikipedia, for simplicity's sake.</p>
  <h3>Chess960</h3>
  <p>The situation changes if the game is Chess960, simply because the legal initial square for the white rook could be <em>either g1 or h1</em>. We cannot be sure <strong>without knowing the initial position.</strong> We cannot ascertain which rook has the kingside castling rights.</p>
  <p>If the FEN given above was used here, it would confer the castling rights on the rook on the h-file, as <strong>the outermost rook is assumed to be the one with the castling rights, by default</strong>. It would also mean that Black can castle <em>only on the a-side</em> (queenside, in other words).</p>
  <p>As a matter of fact, the <strong>initial position for this game</strong> was actually</p>
  <blockquote>
  <p>rnbnkq<strong>r</strong>b/pppppppp/8/8/8/8/PPPPPPPP/RNBNKQ<strong>R</strong>B w KQkq -</p>
  </blockquote>
  <p>If you notice the bold R's, you'll see that the legal square for the white  kingside rook (the one involved in h-side castling) is actually <strong>g1, not h1</strong>. Similarly, the home square of the black 'kingside' rook is <strong>g8, not h8.</strong></p>
  <p>This means that using normal FEN not only confers the castling rights to the <strong>wrong white rook</strong>, it also <strong>fails to indicate the ability of Black to castle kingside.</strong> It's because normal FEN assumes the initial squares of the rooks to be on the a- and h-files only.</p>
  <p>Hence, to avoid the ambiguity caused by normal FEN, X-FEN records the position as</p>
  <blockquote>
  <p>rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w <strong>G</strong>kq - 4 11</p>
  </blockquote>
  <p>The G (in bold) shows that the castling rights on the kingside are <strong>with the rook on the g-file, not with that on the h-file.</strong> This is the <strong>inner</strong> rook. Similarly, it ensures that Black's castling rights on the kingside aren't ignored.</p>
  <p>The queenside castling possibility for Black is recorded normally as there is no ambiguity.</p>
  <h2>Summary</h2>
  <p>Recording castling in Chess960 using X-FEN works as follows:</p>
  <ul>
  <li><p>Just like normal FEN, if the two rooks are on the <em>opposite sides of the king.</em></p>
  </li>
  <li><p>Still like normal FEN, if both rooks are on <em>the same side of the king</em>, with the <strong>outermost rook having the right to castle.</strong></p>
  </li>
  <li><p>Using the letter (capital for White, small for Black) of the file of the rook permitted to castle, when both rooks are on the <em>same side of the king</em>, with the <strong>innermost rook having the right to castle</strong>. In the above example, <strong>G</strong> is used to indicate that the inner rook of White (on the g-file) has the right to castle.</p>
  </li>
  </ul>
  <p>Hope that's clear, feel free to ask if there's any confusion!</p>
  <h3>Note: Special case</h3>
  <p>In the unusual scenario of <strong>three or more</strong> rooks (due to underpromotion) being on the same side of the king, with the king yet to castle, there would be an <strong>outermost rook,</strong> an <strong>innermost rook</strong> and one or more rooks <strong>in between</strong>. In such a case, the outermost rook is treated the same way as above, and <strong>any other inner rook</strong> is identified by its file (depending on which has the right to castle).</p>
  <hr />
  <p>For the curious, here's the PGN of the entire example game.</p>
  <pre><code>[Event &quot;SmirfGUI Computerchess Game&quot;] [Site &quot;CHESSBOX&quot;] [Date &quot;2005.06.19&quot;] [Time &quot;10:22:29&quot;] [Round &quot;Test&quot;] [White &quot;White&quot;] [Black &quot;Black&quot;] [Result &quot;*&quot;] [Annotator &quot;R. Scharnagl&quot;] [SetUp &quot;1&quot;] [FEN &quot;rnbnkqrb/pppppppp/8/8/8/8/PPPPPPPP/RNBNKQRB w KQkq - 0 1&quot;] 1. h4 g6 2. g3 Bf6 3. a4 Qh6 4. Ra3 Bxh4 5. gxh4 Qxh4 6. Qh3 Qxh3 7. Rxh3 Ne6 8. Bf3 d6 9. Nbc3 Ng5 10. Rhh1 Bf5 11. O-O * 
  </code></pre>
  <hr />
  <p>Image and PGN courtesy Wikipedia</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-15T00:30:47.737Z
Answers.Text: Deleted Comment
Answers.UserDisplayName: BOBONA
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-13T22:45:41.750Z
Answers.Text: In retrospect, I wonder if it would have been easier or more difficult to, for notational purposes, treat a rook which is capable of castling, or a pawn which is eligible to be captured *en passant*, as different types of pieces from normal rooks and pawns?  I would think such a distinction would be useful in diagrams, and would avoid the need to have separate notations for such things.
Answers.UserDisplayName: supercat
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-05T09:21:39.243Z
Answers.Text: Why didn't they use the third method (name of the file) in all cases? That's for some kind of compatibility with regular chess?
Answers.UserDisplayName: user1583209
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-05T10:05:14.313Z
Answers.Text: @user1583209 Exactly, that makes X-FEN compatible with standard chess, so if you are recording the position arising in a normal chess have, the X-FEN and the FEN would be identical. This makes the whole thing easier for software developers, too -- they don't have to separately program chess programs for recording the position in normal and Chess960 games.
Answers.UserDisplayName: Myungjin Hyun
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-05T10:14:35.973Z
Answers.Text: @user1583209 As a matter of fact, Shredder uses ShredderFEN, which goes by the third method in all cases, regardless of whether the game is standard chess or Chess960. So does Fritz 9. While that would be more consistent and simple, X-FEN goes for extra complexity to enable backward compatibility.
Answers.UserDisplayName: Myungjin Hyun
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-05T10:17:42.483Z
Answers.Text: @user1583209 I meant *game*, not *have* in my first comment over here. Autocorrect's to blame!
Answers.UserDisplayName: Myungjin Hyun
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-05T08:33:11.097Z
Answers.LastActivityDate: 2017-12-05T13:37:01.200Z
Answers.LastEditDate: 2020-06-17T09:59:59.497Z
Answers.UserDisplayName: Myungjin Hyun
Body: <p>I understand that a modified version of FEN notation is needed to properly record a Chess960 game. </p>
  
  <p>I know that en passant is only slightly different, (an en passant possibility is only recorded if there are adjacent enemy pieces.)</p>
  
  <p>Reading through the Wikipedia article on X-FEN, I don't understand how to record castling. I ask because I am in the middle of creating a chess app, and I want to store game states with FEN.</p>
  
  <p>Can someone explain how castling is recorded in X-FEN notation? Thanks :D</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-05T07:38:31.173Z
Comments.Text: Do you understand castling in Chess960? It would be easy to answer this question if you did.
Comments.UserDisplayName: Myungjin Hyun
Tags: <fen>
Title: How does X-FEN (Chess960 FEN) differentiate from traditional FEN notation?
ThreadText: # How does X-FEN (Chess960 FEN) differentiate from traditional FEN notation?
  
  (Asked by: username_0 on 2017-12-05)
  
  I understand that a modified version of FEN notation is needed to properly record a Chess960 game.
  
  I know that en passant is only slightly different, (an en passant possibility is only recorded if there are adjacent enemy pieces.)
  
  Reading through the Wikipedia article on X-FEN, I don't understand how to record castling. I ask because I am in the middle of creating a chess app, and I want to store game states with FEN.
  
  Can someone explain how castling is recorded in X-FEN notation? Thanks :D
  
  **Tags:** fen
  
  > **Comments:**
  > **username_1**: Do you understand castling in Chess960? It would be easy to answer this question if you did.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-12-05. Score: 5 | Accepted answer
  
  # Let's start at the beginning
  
  To understand X-FEN for castling in Chess960, it helps if you first understand castling in Chess960. Castling rules are slightly different in Chess960, hence there comes a need for X-FEN. I believe it's the major source for your confusion.
  
  **Minor Note 1** X-FEN is used not just for Chess960 but for many other variants as well (Capablanca chess, Janus chess, Chess480, etc.)
  
  ## Castling in Chess960
  
  Castling in chess960 is done on two sides: **the a-side and the h-side**, analogous to queenside and kingside castling respectively. The final positions after castling are the same in Chess960 and in standard chess.
  
  The terms a-side and h-side are used as the initial board configuration is randomized, and what is *queenside* in normal chess needn't be so in Chess960 (the same applies for kingside.).
  
  ## Why FEN is insufficient for Chess960
  
  FEN is sufficient for standard chess, as there are only *two initial squares for the rooks, on the a-file and the h-file*.If a rook from the kingside somehow gets to say, the c-file, there is no question of allowing queenside castling with it as it isn't on the right square. (More on this in an example.)
  
  In chess960, the rooks have *many* possible initial squares. In the course of a game, both the rooks could end up on the same side of the king. Now, if FEN is used, there is no way of clearly knowing which rook has the castling rights (without knowing the initial position) as either could be occupying the *legal* square for castling. As a matter of fact, X-FEN assumes by default the **outermost rook in such cases to have the castling rights,** but that needn't be the case always.
  
  ## An example to make my point clear
  
  [![A situation involving X-FEN](https://i.sstatic.net/r5Cwh.jpg)](https://i.sstatic.net/r5Cwh.jpg)
  
  ### Standard Chess
  
  If the above position occurred in a standard chess game, the FEN would simply be
  
  > rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Kq - 4 11
  
  This is because White can castle legally on the kingside, with the rook on the h-file. The rook on the g-file would play no role in castling, simply because that isn't on the *legal square for kingside castling*.
  
  Likewise, Black can castle only on the queenside, hence the FEN has a **q** for the castling rights of Black. The rook on g8 is irrelevant.
  
  **Minor Note 2** Precise readers might point out that the number of moves and half-moves required to arrive at the position shown, in a normal chess game, might not tally with the values given in the FEN. That is quite possibly true, but I stuck to the value given for the Chess960 game (for the same position) on Wikipedia, for simplicity's sake.
  
  ### Chess960
  
  The situation changes if the game is Chess960, simply because the legal initial square for the white rook could be *either g1 or h1*. We cannot be sure **without knowing the initial position.** We cannot ascertain which rook has the kingside castling rights.
  
  If the FEN given above was used here, it would confer the castling rights on the rook on the h-file, as **the outermost rook is assumed to be the one with the castling rights, by default**. It would also mean that Black can castle *only on the a-side* (queenside, in other words).
  
  As a matter of fact, the **initial position for this game** was actually
  
  > rnbnkq**r**b/pppppppp/8/8/8/8/PPPPPPPP/RNBNKQ**R**B w KQkq -
  
  If you notice the bold R's, you'll see that the legal square for the white kingside rook (the one involved in h-side castling) is actually **g1, not h1**. Similarly, the home square of the black 'kingside' rook is **g8, not h8.**
  
  This means that using normal FEN not only confers the castling rights to the **wrong white rook**, it also **fails to indicate the ability of Black to castle kingside.** It's because normal FEN assumes the initial squares of the rooks to be on the a- and h-files only.
  
  Hence, to avoid the ambiguity caused by normal FEN, X-FEN records the position as
  
  > rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w **G**kq - 4 11
  
  The G (in bold) shows that the castling rights on the kingside are **with the rook on the g-file, not with that on the h-file.** This is the **inner** rook. Similarly, it ensures that Black's castling rights on the kingside aren't ignored.
  
  The queenside castling possibility for Black is recorded normally as there is no ambiguity.
  
  ## Summary
  
  Recording castling in Chess960 using X-FEN works as follows:
  
  * Just like normal FEN, if the two rooks are on the *opposite sides of the king.*
  * Still like normal FEN, if both rooks are on *the same side of the king*, with the **outermost rook having the right to castle.**
  * Using the letter (capital for White, small for Black) of the file of the rook permitted to castle, when both rooks are on the *same side of the king*, with the **innermost rook having the right to castle**. In the above example, **G** is used to indicate that the inner rook of White (on the g-file) has the right to castle.
  
  Hope that's clear, feel free to ask if there's any confusion!
  
  ### Note: Special case
  
  In the unusual scenario of **three or more** rooks (due to underpromotion) being on the same side of the king, with the king yet to castle, there would be an **outermost rook,** an **innermost rook** and one or more rooks **in between**. In such a case, the outermost rook is treated the same way as above, and **any other inner rook** is identified by its file (depending on which has the right to castle).
  
  ---
  
  For the curious, here's the PGN of the entire example game.
  
  ```
  [Event "SmirfGUI Computerchess Game"] [Site "CHESSBOX"] [Date "2005.06.19"] [Time "10:22:29"] [Round "Test"] [White "White"] [Black "Black"] [Result "*"] [Annotator "R. Scharnagl"] [SetUp "1"] [FEN "rnbnkqrb/pppppppp/8/8/8/8/PPPPPPPP/RNBNKQRB w KQkq - 0 1"] 1. h4 g6 2. g3 Bf6 3. a4 Qh6 4. Ra3 Bxh4 5. gxh4 Qxh4 6. Qh3 Qxh3 7. Rxh3 Ne6 8. Bf3 d6 9. Nbc3 Ng5 10. Rhh1 Bf5 11. O-O * 
  
  ```
  
  ---
  
  Image and PGN courtesy Wikipedia
  
  > **Comments:**
  > **username_3**: Why didn't they use the third method (name of the file) in all cases? That's for some kind of compatibility with regular chess?  
  > **username_1**: @username_3 Exactly, that makes X-FEN compatible with standard chess, so if you are recording the position arising in a normal chess have, the X-FEN and the FEN would be identical. This makes the whole thing easier for software developers, too -- they don't have to separately program chess programs for recording the position in normal and Chess960 games.  
  > **username_1**: @username_3 As a matter of fact, Shredder uses ShredderFEN, which goes by the third method in all cases, regardless of whether the game is standard chess or Chess960. So does Fritz 9. While that would be more consistent and simple, X-FEN goes for extra complexity to enable backward compatibility.  
  > **username_1**: @username_3 I meant *game*, not *have* in my first comment over here. Autocorrect's to blame!  
  > **username_0**: Deleted Comment  
  > **username_2**: In retrospect, I wonder if it would have been easier or more difficult to, for notational purposes, treat a rook which is capable of castling, or a pawn which is eligible to be captured *en passant*, as different types of pieces from normal rooks and pawns?  I would think such a distinction would be useful in diagrams, and would avoid the need to have separate notations for such things.  
  
  ---
  
  