Repository: thomas-mauran/chess-tui (language: rust)

Issue:
Material difference bug when castling
## Description

When doing a castle, the material changes by adding a rook in the opponent materials

## To Reproduce

Do a castle and check the materials

## Expected behavior

Don't add a rook when castling

## Screenshots

<img width="1262" alt="Capture d’écran, le 2024-11-17 à 14 02 44" src="https://github.com/user-attachments/assets/d2a1aaf8-43c3-485d-ae89-966cf0abdfd1">

## Environment

Add a description of the systems where you are observing the issue. For example:
- OS: MacOS
- Terminal Emulator: Warp
- Crate version: 1.3.0
- Backend: crossterms




Discussion / hints:

Fix patch:
diff --git a/src/board.rs b/src/board.rs
index b7c89ae..6f52afd 100644
--- a/src/board.rs
+++ b/src/board.rs
@@ -702,16 +702,21 @@ impl Board {
             (_, None) => {}
             (_, Some(piece)) => {
                 let piece_color = get_piece_color(self.board, to);
-                if let Some(piece_color) = piece_color {
+                // We check if there is a piece and we are not doing a castle
+                if piece_color.is_some()
+                    && (piece_type_to != Some(PieceType::Rook)
+                        && piece_color != Some(self.player_turn))
+                {
                     match piece_color {
-                        PieceColor::Black => {
+                        Some(PieceColor::Black) => {
                             self.white_taken_pieces.push(piece);
                             self.white_taken_pieces.sort();
                         }
-                        PieceColor::White => {
+                        Some(PieceColor::White) => {
                             self.black_taken_pieces.push(piece);
                             self.black_taken_pieces.sort();
                         }
+                        _ => {}
                     }
                 }
             }


Test patch: