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

Issue:
Promotion not working for the bots

## Description

Currently, the bot can't promote its pawn

## To Reproduce

Play a game and make the bot promote, we need to analyse what the UCI protocols gives us when there is a promotion and adjust the code accordingly.


## Expected behavior

<!--
A clear and concise description of what you expected to happen.
-->

## Screenshots

<img width="1253" alt="Capture d’écran, le 2024-11-17 à 20 44 12" src="https://github.com/user-attachments/assets/e906b90a-5e30-4b17-9e8a-b92b1520773f">

## Environment

any




Discussion / hints:

Fix patch:
diff --git a/src/board.rs b/src/board.rs
index 6d2c2c4..b7c89ae 100644
--- a/src/board.rs
+++ b/src/board.rs
@@ -483,10 +483,26 @@ impl Board {
         let to_y = get_int_from_char(converted_move.chars().nth(2));
         let to_x = get_int_from_char(converted_move.chars().nth(3));
 
+        let mut promotion_piece: Option<PieceType> = None;
+        if movement.chars().count() == 5 {
+            promotion_piece = match movement.chars().nth(4) {
+                Some('q') => Some(PieceType::Queen),
+                Some('r') => Some(PieceType::Rook),
+                Some('b') => Some(PieceType::Bishop),
+                Some('n') => Some(PieceType::Knight),
+                _ => None,
+            };
+        }
+
         self.move_piece_on_the_board(
             &Coord::new(from_y as u8, from_x as u8),
             &Coord::new(to_y as u8, to_x as u8),
         );
+
+        if promotion_piece.is_some() {
+            self.board[to_y as usize][to_x as usize] =
+                Some((promotion_piece.unwrap(), self.player_turn));
+        }
         if self.is_bot_starting {
             self.flip_the_board();
         }


Test patch: