Created attachment 134081 [details] A bug or a feature in castling? SUMMARY STEPS TO REPRODUCE 1. 2. 3. OBSERVED RESULT EXPECTED RESULT SOFTWARE/OS VERSIONS Windows: macOS: Linux/KDE Plasma: ArcoLInux (available in About System) KDE Plasma Version: KDE Frameworks Version: Qt Version: ADDITIONAL INFORMATION
Created attachment 144945 [details] test case O-O-O
Created attachment 144946 [details] test case O-O
This is a bug in the castling code for Knights. It is reproducible for both king side and queen side castling. The rules for castling are: * king has not moved * rook has not moved * no pieces between the king and rook * king is not in check * king does not cross over a square that is attacked by the opponent's pieces * king does not end the move on a square attacked by the opponent's pieces All of these rules are passed in the attached game. The unusual situation is that the rook was captured - but the rook never "moved" so it passed the rules tests. A human would recognize the piece was not a rook and therefore not castle. An additional rule must be formulated specifically for a computer to test if the piece is a rook. It would reside in Knights castling routines. Attached are game files that can be used to test the code. The NEXT move in the game will be the castling move, and will demonstrate the error.
Created attachment 147653 [details] Patch file Bug 430403 Attached is a patch to fix this bug. The bug allows the castling rook to be captured by either a knight or bishop. If the rook has not moved, then the present code assumes the position is occupied by a rook and will castle with the piece that is in that position. The present code will not allow castling if the capturing piece is a rook or a queen, since these will immediately put the king into check and prevent castling. The patch is a simple check to see if the rook's position actually contains a rook. The color could also be checked, but this is not necessary. If the location is occupied by an opponent's rook (different color) it will not allow castling due to that rook putting the king into check.
Git commit ce7a9b46041295c61f9fbd07724e5c739ef8a923 by Alexander Semke, on behalf of David Kaye. Committed on 15/04/2022 at 08:35. Pushed by asemke into branch 'master'. Don't allow to perform castling if the non-moved rook was already captured and its position is occupied by another piece. FIXED-IN: 22.08 M +2 -2 src/rules/chessrules.cpp https://invent.kde.org/games/knights/commit/ce7a9b46041295c61f9fbd07724e5c739ef8a923