Answers.Body: <p>Edit: This answer only deals with kingside castling; the figures have to be revised if you also consider queenside castling.</p>
  <p>The three first steps:</p>
  <p><strong>There are 90 positions where n(P)=1</strong></p>
  <p>For White to be able to castle short at once, he needs to have Kf1, Rg1 in the initial position. Then there are 5 possible spots from the second rook, 3 for one bishop and 2 for the other one, and finally 3 remaining spots for the queen. The knights go to the last two spots.</p>
  <p><strong>There are 100 positions where n(P)=2</strong></p>
  <p>36 of them with Kf1, Ng1, Rh1: White can play 1.Nf3 or 1.Nh3 and 2.0-0</p>
  <p>36 of them with Kg1, Nf1, Rh1: White can play 1.Ne3 or 1.Ng3 and 2.0-0</p>
  <p>28 of them with Rg1, Nf1, Ke1: White can play 1.Ng3 or 1.Ne3 and 2.0-0</p>
  <p><strong>There are 236 positions where n(P)=3</strong>
  <em>please double-check this part</em></p>
  <p>Here are the different configurations and the number of relevant positions:</p>
  <p>xxxxxQKR 18<br>
  xxxxxBKR 36<br>
  xxxxxRKR 18<br>
  xxxxxKQR 18<br>
  xxxxxKBR 24<br>
  xxxxKNNR 8<br>
  xxxKNNRx 6<br>
  xxxKNRNx 6<br>
  xxxKRNNx 6<br>
  xxxxKBRx 24<br>
  xxxxKQRx 18<br>
  xxxxKRBx 36<br>
  xxxxKRQx 18<br></p>
  <p>Total:236</p>
  <p><em>Edit : removed 2 cases after checking the <a href="https://chess960.net/how-to-play/" rel="nofollow noreferrer">rules</a>: the path to g1 must be open for the king (only the right-hand rook can be in the way)</em></p>
  <p>Once we reach <strong>n(P)=4</strong>, we cannot ignore Black's play anymore: for instance, QNRNKBBR <em>looks like</em> it should have n=5, but actually it has n=4 because of the sequence 1.f4 b5 2.Bxa7 Qxg2 3.Bxg2 Nc6 4.0-0. Counting by hand becomes too fastidious and hazardous: a software program is needed.</p>
  <hr />
  <p>On the other hand, after clarification by the OP, I believe <strong>7 to be the maximum</strong> value of the function P-&gt;n(P).</p>
  <p>If Black wasn't allowed to &quot;help&quot; we could build only 2 positions with n(P)=9; Here is one, the other is similar with RKBBNNQR on the first rank.</p>
  <pre><code>[FEN &quot;rkqnnbbr/pppppppp/8/8/8/8/PPPPPPPP/RKQNNBBR w - - 0 1&quot;]
  </code></pre>
  <p>In a series problem where White plays alone he would need 9 moves in order to castle. But since Black moves are taken into account, White actually can castle on move 7 from that diagram if the game goes something like 1.b3 d5 2.Qa3 Qe6 3.Nb2 Qxe2 4.Ned3 Qxf2 5.Bxf2 Nc6 6.Be2 0-0-0 7.0-0.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-22T08:57:40.737Z
Answers.Text: Alternatively, Black can be a spoilsport and throw a Q in the works ;-) The question could be solved in both cases with problemist software and some patience (indeed, only 960 positions to check), but offhand I have no idea if e.g. Popeye is 960-compliant.
Answers.UserDisplayName: Hauke Reddmann
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-19T06:07:15.513Z
Answers.Text: is the 90 positions for n(P)=1 a coincidence with the 90 here? https://chess.stackexchange.com/questions/37082/how-many-chess960-positions-exist-in-which-castling-on-1-side-does-not-require-m (960-90=870)
Answers.UserDisplayName: BCLC
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-20T13:08:01.507Z
Answers.Text: @BCLC : as far as I understand, this is just an coincidence because both questions are not directly related.
Answers.UserDisplayName: Evargalo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-30T10:31:43.247Z
Answers.LastActivityDate: 2021-12-20T13:06:12.323Z
Answers.LastEditDate: 2021-12-20T13:06:12.323Z
Answers.UserDisplayName: Evargalo
Body: <p>As you know, in the initial position Chess960 the king lies between the two rooks. <a href="https://chess960.net/how-to-play/" rel="nofollow noreferrer">Here</a> are the rules for castling.</p>
  <p>For a starting position <em>P</em>, let <em>n</em>(<em>P</em>) be the minimal number of moves that White needs to legally castle kingside. How many positions are there such that <em>n</em>(<em>P</em>) = 1, <em>n</em>(<em>P</em>) = 2, and so on?</p>
  <p>There are cases where we can castle in the first move, namely when the king on f1 and the rook on g1. There are also other extreme cases with the king on b1 and the rook on c1, so then we have to make space.</p>
  <p>Maybe some engines can solve this question.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-29T17:39:23.887Z
Comments.Text: If you can count you can work out the answer yourself. There are only 960 positions to consider. The clue is in the name.
Comments.UserDisplayName: Brian Towers
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-29T20:17:17.690Z
Comments.Text: Yes, but 1. I am mathematician, so I can count :). 2. Since I am a mathematician, I am lazy so I would like to know whether there are general principles which would avoid to count. And how n(P) is distributed.
Comments.UserDisplayName: Davide Giraudo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-30T10:17:28.613Z
Comments.Text: @DavideGiraudo : *1.I am mathematician, so I can count (...) 2. Since I am a mathematician, I am lazy* : I could name several counterexamples for both claims !
Comments.UserDisplayName: Evargalo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-31T06:32:28.340Z
Comments.Text: Is n(P) the minimal number of moves before White can castle if he plays alone, or in any possible game (I.e. Black can help)?
Comments.UserDisplayName: Evargalo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-31T08:17:05.510Z
Comments.Text: Ah I missed this aspect. I am interested in the minimum in any possible game so like the example of your answer shows, black can help to make space by taking a pawn in the second row. In this way, they do not have to spend a time.
Comments.UserDisplayName: Davide Giraudo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-12-20T16:59:16.130Z
Comments.Text: @TobyHarnish What do you mean by the most basic things (you see that I can also make you misunderstood)? It was just meant to be a joke.
Comments.UserDisplayName: Davide Giraudo
Tags: <chess-variants><castling><mathematics><chess960>
Title: Minimal number of moves before castling in Chess960
ThreadText: # Minimal number of moves before castling in Chess960
  
  (Asked by: username_0 on 2019-08-29)
  
  As you know, in the initial position Chess960 the king lies between the two rooks. [Here](https://chess960.net/how-to-play/) are the rules for castling.
  
  For a starting position *P*, let *n*(*P*) be the minimal number of moves that White needs to legally castle kingside. How many positions are there such that *n*(*P*) = 1, *n*(*P*) = 2, and so on?
  
  There are cases where we can castle in the first move, namely when the king on f1 and the rook on g1. There are also other extreme cases with the king on b1 and the rook on c1, so then we have to make space.
  
  Maybe some engines can solve this question.
  
  **Tags:** chess-variants, castling, mathematics, chess960
  
  > **Comments:**
  > **username_1**: If you can count you can work out the answer yourself. There are only 960 positions to consider. The clue is in the name.  
  > **username_0**: Yes, but 1. I am mathematician, so I can count :). 2. Since I am a mathematician, I am lazy so I would like to know whether there are general principles which would avoid to count. And how n(P) is distributed.  
  > **username_2**: @DavideGiraudo : *1.I am mathematician, so I can count (...) 2. Since I am a mathematician, I am lazy* : I could name several counterexamples for both claims !  
  > **username_2**: Is n(P) the minimal number of moves before White can castle if he plays alone, or in any possible game (I.e. Black can help)?  
  > **username_0**: Ah I missed this aspect. I am interested in the minimum in any possible game so like the example of your answer shows, black can help to make space by taking a pawn in the second row. In this way, they do not have to spend a time.  
  > **username_0**: @TobyHarnish What do you mean by the most basic things (you see that I can also make you misunderstood)? It was just meant to be a joke.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-08-30. Score: 9 | Accepted answer
  
  Edit: This answer only deals with kingside castling; the figures have to be revised if you also consider queenside castling.
  The three first steps:
  There are 90 positions where n(P)=1
  For White to be able to castle short at once, he needs to have Kf1, Rg1 in the initial position. Then there are 5 possible spots from the second rook, 3 for one bishop and 2 for the other one, and finally 3 remaining spots for the queen. The knights go to the last two spots.
  There are 100 positions where n(P)=2
  36 of them with Kf1, Ng1, Rh1: White can play 1.Nf3 or 1.Nh3 and 2.0-0
  36 of them with Kg1, Nf1, Rh1: White can play 1.Ne3 or 1.Ng3 and 2.0-0
  28 of them with Rg1, Nf1, Ke1: White can play 1.Ng3 or 1.Ne3 and 2.0-0
  There are 236 positions where n(P)=3
  please double-check this part
  Here are the different configurations and the number of relevant positions:
  xxxxxQKR 18
  xxxxxBKR 36
  xxxxxRKR 18
  xxxxxKQR 18
  xxxxxKBR 24
  xxxxKNNR 8
  xxxKNNRx 6
  xxxKNRNx 6
  xxxKRNNx 6
  xxxxKBRx 24
  xxxxKQRx 18
  xxxxKRBx 36
  xxxxKRQx 18
  Total:236
  Edit : removed 2 cases after checking the rules: the path to g1 must be open for the king (only the right-hand rook can be in the way)
  Once we reach n(P)=4, we cannot ignore Black's play anymore: for instance, QNRNKBBR looks like it should have n=5, but actually it has n=4 because of the sequence 1.f4 b5 2.Bxa7 Qxg2 3.Bxg2 Nc6 4.0-0. Counting by hand becomes too fastidious and hazardous: a software program is needed.
  
  On the other hand, after clarification by the OP, I believe 7 to be the maximum value of the function P->n(P).
  If Black wasn't allowed to "help" we could build only 2 positions with n(P)=9; Here is one, the other is similar with RKBBNNQR on the first rank.
  [FEN "rkqnnbbr/pppppppp/8/8/8/8/PPPPPPPP/RKQNNBBR w - - 0 1"]
  
  In a series problem where White plays alone he would need 9 moves in order to castle. But since Black moves are taken into account, White actually can castle on move 7 from that diagram if the game goes something like 1.b3 d5 2.Qa3 Qe6 3.Nb2 Qxe2 4.Ned3 Qxf2 5.Bxf2 Nc6 6.Be2 0-0-0 7.0-0.
  
  > **Comments:**
  > **username_3**: Alternatively, Black can be a spoilsport and throw a Q in the works ;-) The question could be solved in both cases with problemist software and some patience (indeed, only 960 positions to check), but offhand I have no idea if e.g. Popeye is 960-compliant.  
  > **username_4**: is the 90 positions for n(P)=1 a coincidence with the 90 here? https://chess.stackexchange.com/questions/37082/how-many-chess960-positions-exist-in-which-castling-on-1-side-does-not-require-m (960-90=870)  
  > **username_2**: @username_4 : as far as I understand, this is just an coincidence because both questions are not directly related.  
  
  ---
  
  