diff --git a/htdocs/chess.js b/htdocs/chess.js index 0ee7cb73650d099427d3dceb745f3a99046b7f4c..e101dc11b295b6e02044bfb3c06026cc79de53fd 100644 --- a/htdocs/chess.js +++ b/htdocs/chess.js @@ -123,6 +123,58 @@ function highlightMoves(piece, row, col) { 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; + } + } + } return moves;