Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Connect4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Durand Ulysse
Connect4
Commits
1e59bd4a
Commit
1e59bd4a
authored
1 month ago
by
oumaima laklouch
Browse files
Options
Downloads
Patches
Plain Diff
Update server.js
parent
6425a898
Branches
main
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.js
+36
-40
36 additions, 40 deletions
server.js
with
36 additions
and
40 deletions
server.js
+
36
−
40
View file @
1e59bd4a
...
...
@@ -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) {
}
}
// D
ans l’autre direction
// D
irection 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment