Skip to content
Snippets Groups Projects
Commit 1e59bd4a authored by oumaima laklouch's avatar oumaima laklouch
Browse files

Update server.js

parent 6425a898
Branches main
No related tags found
No related merge requests found
......@@ -170,24 +170,22 @@ function checkWin(board, row, col) {
const WINNING_LENGTH = 4;
const directions = [
[0, 1], // horizontal
[1, 0], // vertical
[1, 1], // diagonale descendante
[1, -1], // diagonale montante
[0, 1], // horizontal
[1, 0], // vertical
[1, 1], // diagonale descendante
[1, -1] // diagonale montante
];
for (const [dx, dy] of directions) {
let count = 1;
// Dans une direction
for (let step = 1; step < WINNING_LENGTH; step++) {
const newRow = row + step * dx;
const newCol = col + step * dy;
if (
newRow >= 0 &&
newRow < ROWS &&
newCol >= 0 &&
newCol < COLS &&
newRow >= 0 && newRow < ROWS &&
newCol >= 0 && newCol < COLS &&
board[newRow][newCol] === player
) {
count++;
......@@ -196,15 +194,13 @@ function checkWin(board, row, col) {
}
}
// Dans l’autre direction
// Direction opposée
for (let step = 1; step < WINNING_LENGTH; step++) {
const newRow = row - step * dx;
const newCol = col - step * dy;
if (
newRow >= 0 &&
newRow < ROWS &&
newCol >= 0 &&
newCol < COLS &&
newRow >= 0 && newRow < ROWS &&
newCol >= 0 && newCol < COLS &&
board[newRow][newCol] === player
) {
count++;
......@@ -216,7 +212,7 @@ function checkWin(board, row, col) {
if (count >= WINNING_LENGTH) {
return player;
}
}
return null;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment