Answers.Body: <p>Normal Stockfish can handle FRC positions. You just need to tell it that it is a FRC game - which shouldn't be a problem since it should be apparent from the FEN you give it.</p>
  <p>As can be seen from the <a href="https://github.com/official-stockfish/Stockfish/blob/02ef1f4496965b5ad8c26ac6bc18245eaffae2ea/src/position.h#L380" rel="nofollow noreferrer">code</a>, normal Stockfish has a &quot;isChess960&quot; boolean which, as its name implies, tells the engine if the position is a Chess960 position and calls the relevant functions if true.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T13:34:16.180Z
Answers.Text: How can it tell it is chess960 from the FEN?
Answers.UserDisplayName: qwr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T13:35:07.863Z
Answers.Text: @qwr the FEN gives castling rights. If you tell Stockfish it can castle kingside, it will know O-O is legal even if the king and rook aren't currently on e1 and h1.
Answers.UserDisplayName: Allure
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T13:54:02.060Z
Answers.Text: I see, so Stockfish knows how to castle chess960 style by default? That would be good to add to you answer.
Answers.UserDisplayName: qwr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T16:01:50.890Z
Answers.Text: Do you have further code links showing how Stockfish uses that flag to successfully castle when the king and rook are on non-standard squares? Because I set up positions where I had told Stockfish via the fen that both sides had full castling rights and where the best move was clearly castling (only way to avoid material loss) and Stockfish resolutely refused to even consider the move. Presence of the flag indicates intent but not actual implementation.
Answers.UserDisplayName: Brian Towers
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T16:13:23.850Z
Answers.Text: @BrianTowers are you sure your FEN is right? Try this one, White has only one winning move, and Stockfish finds the mate in 1. 2qqq3/2qqq3/8/8/8/1Q6/PPPPPPP1/1k3K1R w K - 0 1
Answers.UserDisplayName: Allure
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T16:23:17.587Z
Answers.Text: My Stockfish gives g3 as the best move although I agree O-O looks much better. My version is the Windows version from 4/12/22
Answers.UserDisplayName: Brian Towers
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T16:25:50.530Z
Answers.Text: Interesting that GothamChess also seems to think that [Stockfish 15 has problems castling](https://www.youtube.com/watch?v=wFALbm4gFoc)
Answers.UserDisplayName: Brian Towers
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T23:51:59.657Z
Answers.Text: @BrianTowers I don't know then. Lichess gives 1. O-O. https://lichess.org/analysis/standard/2qqq3/2qqq3/8/8/8/1Q6/PPPPPPP1/1k3K1R_w_K_-_0_1
Answers.UserDisplayName: Allure
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-30T18:46:48.840Z
Answers.Text: I'm able to concoct this situation: https://lichess.org/analysis/standard/k4r2/8/8/8/8/p1p1p1p1/P1P1P1P1/1BRKRB2_w_KQ_-_0_1
  Testing on stockfish executable for windows:
  `position fen "k4r2/8/8/8/8/p1p1p1p1/P1P1P1P1/1BRKRB2 w KQ - 0 1"`
  `go depth 6`
  result: stockfish knows. This isn't just lichess being smart.
Answers.UserDisplayName: CubicInfinity
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-03T02:28:16.150Z
Answers.Text: There might be limitations. https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation#FEN_adjustment_for_chess_variants_like_Chess960
  Consider if one of the rooks moves to the other side of the king. In this situation, how will Stockfish know which rook started there without additional context?
Answers.UserDisplayName: CubicInfinity
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-03T10:13:27.637Z
Answers.Text: @CubicInfinity if two rooks are on the same side of the King, it won't be Chess960 anymore, since Chess960 explicitly requires the King to be in between the Rooks.
Answers.UserDisplayName: Allure
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-06T16:59:11.083Z
Answers.Text: @Allure I don't mean at the start of the game. I mean sometime during play, one of the rooks moves to the other side of the king. At this point it will say castling on that side is still available if the other rook hasn't moved, but Stockfish won't know which rook started there.
Answers.UserDisplayName: CubicInfinity
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T11:10:41.587Z
Answers.LastActivityDate: 2022-12-29T11:10:41.587Z
Answers.UserDisplayName: Allure
Answers.Body: <p>Vanilla Stockfish uses the castling rule given in article 3.8.2 of the <a href="https://handbook.fide.com/chapter/E012018" rel="noreferrer">FIDE Laws of Chess</a>. In that rule the king is always on the e file and the rook either on the a file or h file.</p>
  <p>In Chess960 the files the rooks and kings can be on are different. If they are on the &quot;correct&quot; files then castling will work. If not then castling will not work.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-28T23:04:25.717Z
Answers.Text: Oh, I get it. Because Stockfish doesn't know castling is possible.
Answers.UserDisplayName: CubicInfinity
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-29T14:46:25.480Z
Answers.Text: It seems that just checking the position of king and rooks would not be sufficient even in vanilla chess, as the pieces could have been moved and then moved back to their starting positions, which should rule out castling, but if you're only checking based on current position and not looking at all the previous moves, you might miss that.
Answers.UserDisplayName: Darrel Hoffman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-30T18:52:59.323Z
Answers.Text: See Allure's answer and its comments. It would appear that vanilla Stockfish can do Chess960 so long as the castling rights are included in the FEN.
Answers.UserDisplayName: CubicInfinity
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-28T21:19:50.867Z
Answers.LastActivityDate: 2022-12-28T21:19:50.867Z
Answers.UserDisplayName: Brian Towers
Body: <p>Is vanilla Stockfish perfectly capable of understanding Chess960 games (including the way castling works), or do you need to use something like Fairy-Stockfish to get the best results?</p>
  <p>It seems like normal Stockfish should work, but I want to be sure.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-29T14:31:19.287Z
Comments.Text: normal stockfish knows understand Chess960 but those engine don't know about castling. They don't castle in Chess960. [IIRC](https://www.youtube.com/watch?v=wFALbm4gFoc)
Comments.UserDisplayName: Billy Istiak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-01-03T02:28:50.860Z
Comments.Text: There is a lot of important discussion in the comments to Allure's answer.
Comments.UserDisplayName: CubicInfinity
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-13T07:05:03.910Z
Comments.Text: TLDR is as follows: There are some edge cases and this means that Stockfish may not evaluate a position correctly.
Comments.UserDisplayName: CubicInfinity
Tags: <stockfish><chess960>
Title: Does normal Stockfish handle Chess960?
ThreadText: # Does normal Stockfish handle Chess960?
  
  (Asked by: username_0 on 2022-12-28)
  
  Is vanilla Stockfish perfectly capable of understanding Chess960 games (including the way castling works), or do you need to use something like Fairy-Stockfish to get the best results?
  
  It seems like normal Stockfish should work, but I want to be sure.
  
  **Tags:** stockfish, chess960
  
  > **Comments:**
  > **username_1**: normal stockfish knows understand Chess960 but those engine don't know about castling. They don't castle in Chess960. [IIRC](https://www.youtube.com/watch?v=wFALbm4gFoc)  
  > **username_0**: There is a lot of important discussion in the comments to username_2's answer.  
  > **username_0**: TLDR is as follows: There are some edge cases and this means that Stockfish may not evaluate a position correctly.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2022-12-29. Score: 4 | Accepted answer
  
  Normal Stockfish can handle FRC positions. You just need to tell it that it is a FRC game - which shouldn't be a problem since it should be apparent from the FEN you give it.
  
  As can be seen from the [code](https://github.com/official-stockfish/Stockfish/blob/02ef1f4496965b5ad8c26ac6bc18245eaffae2ea/src/position.h#L380), normal Stockfish has a "isChess960" boolean which, as its name implies, tells the engine if the position is a Chess960 position and calls the relevant functions if true.
  
  > **Comments:**
  > **username_3**: How can it tell it is chess960 from the FEN?  
  > **username_2**: @username_3 the FEN gives castling rights. If you tell Stockfish it can castle kingside, it will know O-O is legal even if the king and rook aren't currently on e1 and h1.  
  > **username_3**: I see, so Stockfish knows how to castle chess960 style by default? That would be good to add to you answer.  
  > **username_4**: Do you have further code links showing how Stockfish uses that flag to successfully castle when the king and rook are on non-standard squares? Because I set up positions where I had told Stockfish via the fen that both sides had full castling rights and where the best move was clearly castling (only way to avoid material loss) and Stockfish resolutely refused to even consider the move. Presence of the flag indicates intent but not actual implementation.  
  > **username_2**: @BrianTowers are you sure your FEN is right? Try this one, White has only one winning move, and Stockfish finds the mate in 1. 2qqq3/2qqq3/8/8/8/1Q6/PPPPPPP1/1k3K1R w K - 0 1  
  > **username_4**: My Stockfish gives g3 as the best move although I agree O-O looks much better. My version is the Windows version from 4/12/22  
  > **username_4**: Interesting that GothamChess also seems to think that [Stockfish 15 has problems castling](https://www.youtube.com/watch?v=wFALbm4gFoc)  
  > **username_2**: @BrianTowers I don't know then. Lichess gives 1. O-O. https://lichess.org/analysis/standard/2qqq3/2qqq3/8/8/8/1Q6/PPPPPPP1/1k3K1R_w_K_-_0_1  
  > **username_0**: I'm able to concoct this situation: https://lichess.org/analysis/standard/k4r2/8/8/8/8/p1p1p1p1/P1P1P1P1/1BRKRB2_w_KQ_-_0_1 Testing on stockfish executable for windows: `position fen "k4r2/8/8/8/8/p1p1p1p1/P1P1P1P1/1BRKRB2 w KQ - 0 1"` `go depth 6` result: stockfish knows. This isn't just lichess being smart.  
  > **username_0**: There might be limitations. https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation#FEN_adjustment_for_chess_variants_like_Chess960 Consider if one of the rooks moves to the other side of the king. In this situation, how will Stockfish know which rook started there without additional context?  
  > **username_2**: @username_0 if two rooks are on the same side of the King, it won't be Chess960 anymore, since Chess960 explicitly requires the King to be in between the Rooks.  
  > **username_0**: @username_2 I don't mean at the start of the game. I mean sometime during play, one of the rooks moves to the other side of the king. At this point it will say castling on that side is still available if the other rook hasn't moved, but Stockfish won't know which rook started there.  
  
  ---
  
  ### Answer by username_4 on 2022-12-28. Score: 6
  
  Vanilla Stockfish uses the castling rule given in article 3.8.2 of the [FIDE Laws of Chess](https://handbook.fide.com/chapter/E012018). In that rule the king is always on the e file and the rook either on the a file or h file.
  
  In Chess960 the files the rooks and kings can be on are different. If they are on the "correct" files then castling will work. If not then castling will not work.
  
  > **Comments:**
  > **username_0**: Oh, I get it. Because Stockfish doesn't know castling is possible.  
  > **username_5**: It seems that just checking the position of king and rooks would not be sufficient even in vanilla chess, as the pieces could have been moved and then moved back to their starting positions, which should rule out castling, but if you're only checking based on current position and not looking at all the previous moves, you might miss that.  
  > **username_0**: See username_2's answer and its comments. It would appear that vanilla Stockfish can do Chess960 so long as the castling rights are included in the FEN.  
  
  ---
  
  