From 9e9e3962bafc70bc5fd474f0292079d9c85be94c Mon Sep 17 00:00:00 2001
From: Adam <adam.elarouti@etu.ec-lyon.fr>
Date: Wed, 26 Mar 2025 09:53:05 +0100
Subject: [PATCH] mange piece

---
 htdocs/chess.js | 66 +++++--------------------------------------------
 1 file changed, 6 insertions(+), 60 deletions(-)

diff --git a/htdocs/chess.js b/htdocs/chess.js
index e101dc1..e88e2dc 100644
--- a/htdocs/chess.js
+++ b/htdocs/chess.js
@@ -116,67 +116,14 @@ function highlightMoves(piece, row, col) {
         if (board[row + direction] && board[row + direction][col] === "") {
             moves.push({ row: row + direction, col });
         }
-        // Prises diagonales
-        let possibleCaptures = [col - 1, col + 1];
-        for (let newCol of possibleCaptures) {
-            if (newCol >= 0 && newCol < 8 && board[row + direction] && noirs.has(board[row + direction][newCol])) {
-                moves.push({ row: row + direction, col: newCol });
-            }
-        }
-    if (piece.toLowerCase() === "t") {
-            // Déplacements vers le haut
-        for (let r = row - 1; r >= 0; r--) {
-            if (board[r][col] === "") {
-                moves.push({ row: r, col });
-            } else {
-                if (noirs.includes(board[r][col])) {
-                    moves.push({ row: r, col }); // Capture possible
-                }
-                if (blancs.includes(board[r][col])) {
-                    break
-                }
-                break; // Bloqué par une pièce
-            }
-        }
-    
-            // Déplacements vers le bas
-            for (let r = row + 1; r < 8; r++) {
-                if (board[r][col] === "") {
-                    moves.push({ row: r, col });
-                } else {
-                    if (noirs.includes(board[r][col])) {
-                        moves.push({ row: r, col });
-                    }
-                    break;
-                }
-            }
-    
-            // Déplacements vers la gauche
-            for (let c = col - 1; c >= 0; c--) {
-                if (board[row][c] === "") {
-                    moves.push({ row, col: c });
-                } else {
-                    if (noirs.includes(board[r][col])) {
-                        moves.push({ row, col: c });
-                    }
-                    break;
-                }
-            }
-    
-            // Déplacements vers la droite
-            for (let c = col + 1; c < 8; c++) {
-                if (board[row][c] === "") {
-                    moves.push({ row, col: c });
-                } else {
-                    if (noirs.includes(board[r][col])) {
-                        moves.push({ row, col: c });
-                    }
-                    break;
-                }
-            }
+        if (noirs.includes(board[row + direction][col + direction])){
+            moves.push({row: row +direction, col: col + direction })
         }
-    
+        if (noirs.includes(board[row + direction][col - direction])){
+            moves.push({row: row +direction, col: col - direction })
+    }
 
+    }
     return moves;
 
 }
@@ -221,5 +168,4 @@ function movePiece(newRow, newCol) {
         console.log("Mouvement invalide !");
         selectedPiece=null;
     }
-}
 }
\ No newline at end of file
-- 
GitLab