7

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.

  • 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) – Billy Istiak Dec 29 '22 at 14:31
  • There is a lot of important discussion in the comments to Allure's answer. – CubicInfinity Jan 03 '23 at 02:28
  • TLDR is as follows: There are some edge cases and this means that Stockfish may not evaluate a position correctly. – CubicInfinity Feb 13 '23 at 07:05

2 Answers2

6

Vanilla Stockfish uses the castling rule given in article 3.8.2 of the FIDE Laws of Chess. 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.

Brian Towers
  • 92,895
  • 10
  • 227
  • 372
  • 3
    Oh, I get it. Because Stockfish doesn't know castling is possible. – CubicInfinity Dec 28 '22 at 23:04
  • 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. – Darrel Hoffman Dec 29 '22 at 14:46
  • 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. – CubicInfinity Dec 30 '22 at 18:52
4

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

Allure
  • 25,298
  • 1
  • 65
  • 143
  • How can it tell it is chess960 from the FEN? – qwr Dec 29 '22 at 13:34
  • 1
    @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. – Allure Dec 29 '22 at 13:35
  • 1
    I see, so Stockfish knows how to castle chess960 style by default? That would be good to add to you answer. – qwr Dec 29 '22 at 13:54
  • 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. – Brian Towers Dec 29 '22 at 16:01
  • 1
    @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 – Allure Dec 29 '22 at 16:13
  • 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 – Brian Towers Dec 29 '22 at 16:23
  • Interesting that GothamChess also seems to think that [Stockfish 15 has problems castling](https://www.youtube.com/watch?v=wFALbm4gFoc) – Brian Towers Dec 29 '22 at 16:25
  • @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 – Allure Dec 29 '22 at 23:51
  • 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. – CubicInfinity Dec 30 '22 at 18:46
  • 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? – CubicInfinity Jan 03 '23 at 02:28
  • @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. – Allure Jan 03 '23 at 10:13
  • @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. – CubicInfinity Jan 06 '23 at 16:59