Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Echecs
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
Elarouti Adam
Echecs
Commits
07cf28a4
Commit
07cf28a4
authored
1 month ago
by
Elarouti Adam
Browse files
Options
Downloads
Patches
Plain Diff
dame roi fou cavalier
parent
e706f75a
Loading
Loading
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/chess.js
+133
-0
133 additions, 0 deletions
htdocs/chess.js
with
133 additions
and
0 deletions
htdocs/chess.js
+
133
−
0
View file @
07cf28a4
...
...
@@ -222,6 +222,139 @@ function highlightMoves(piece, row, col) {
}
}
}
if
(
piece
.
toLowerCase
()
===
"
k
"
)
{
let
directions
=
[
{
dr
:
-
1
,
dc
:
0
},
// Haut
{
dr
:
1
,
dc
:
0
},
// Bas
{
dr
:
0
,
dc
:
-
1
},
// Gauche
{
dr
:
0
,
dc
:
1
},
// Droite
{
dr
:
-
1
,
dc
:
-
1
},
// Diagonale haut-gauche
{
dr
:
-
1
,
dc
:
1
},
// Diagonale haut-droite
{
dr
:
1
,
dc
:
-
1
},
// Diagonale bas-gauche
{
dr
:
1
,
dc
:
1
}
// Diagonale bas-droite
];
for
(
let
{
dr
,
dc
}
of
directions
)
{
let
newRow
=
row
+
dr
;
let
newCol
=
col
+
dc
;
// Vérifie que la nouvelle position est sur l'échiquier
if
(
newRow
>=
0
&&
newRow
<
8
&&
newCol
>=
0
&&
newCol
<
8
)
{
if
(
board
[
newRow
][
newCol
]
===
""
||
noirs
.
includes
(
board
[
newRow
][
newCol
]))
{
moves
.
push
({
row
:
newRow
,
col
:
newCol
});
}
}
}
}
if
(
piece
.
toLowerCase
()
===
"
c
"
)
{
let
movesL
=
[
{
dr
:
-
2
,
dc
:
-
1
},
{
dr
:
-
2
,
dc
:
1
},
// Haut gauche, Haut droite
{
dr
:
2
,
dc
:
-
1
},
{
dr
:
2
,
dc
:
1
},
// Bas gauche, Bas droite
{
dr
:
-
1
,
dc
:
-
2
},
{
dr
:
-
1
,
dc
:
2
},
// Gauche haut, Droite haut
{
dr
:
1
,
dc
:
-
2
},
{
dr
:
1
,
dc
:
2
}
// Gauche bas, Droite bas
];
for
(
let
{
dr
,
dc
}
of
movesL
)
{
let
newRow
=
row
+
dr
;
let
newCol
=
col
+
dc
;
// Vérifie que la nouvelle position est sur l'échiquier
if
(
newRow
>=
0
&&
newRow
<
8
&&
newCol
>=
0
&&
newCol
<
8
)
{
if
(
board
[
newRow
][
newCol
]
===
""
||
noirs
.
includes
(
board
[
newRow
][
newCol
]))
{
moves
.
push
({
row
:
newRow
,
col
:
newCol
});
}
}
}
}
if
(
piece
.
toLowerCase
()
===
"
q
"
)
{
// Déplacements verticaux (haut et bas)
for
(
let
r
=
row
-
1
;
r
>=
0
;
r
--
)
{
// Haut
if
(
board
[
r
][
col
]
===
""
)
{
moves
.
push
({
row
:
r
,
col
});
}
else
{
if
(
noirs
.
includes
(
board
[
r
][
col
]))
{
moves
.
push
({
row
:
r
,
col
});
// Capture possible
}
break
;
// Bloqué par une pièce
}
}
for
(
let
r
=
row
+
1
;
r
<
8
;
r
++
)
{
// Bas
if
(
board
[
r
][
col
]
===
""
)
{
moves
.
push
({
row
:
r
,
col
});
}
else
{
if
(
noirs
.
includes
(
board
[
r
][
col
]))
{
moves
.
push
({
row
:
r
,
col
});
}
break
;
}
}
// Déplacements horizontaux (gauche et droite)
for
(
let
c
=
col
-
1
;
c
>=
0
;
c
--
)
{
// Gauche
if
(
board
[
row
][
c
]
===
""
)
{
moves
.
push
({
row
,
col
:
c
});
}
else
{
if
(
noirs
.
includes
(
board
[
row
][
c
]))
{
moves
.
push
({
row
,
col
:
c
});
}
break
;
}
}
for
(
let
c
=
col
+
1
;
c
<
8
;
c
++
)
{
// Droite
if
(
board
[
row
][
c
]
===
""
)
{
moves
.
push
({
row
,
col
:
c
});
}
else
{
if
(
noirs
.
includes
(
board
[
row
][
c
]))
{
moves
.
push
({
row
,
col
:
c
});
}
break
;
}
}
// Déplacements diagonaux (haut-gauche, haut-droite, bas-gauche, bas-droite)
for
(
let
r
=
row
-
1
,
c
=
col
-
1
;
r
>=
0
&&
c
>=
0
;
r
--
,
c
--
)
{
// Haut-Gauche
if
(
board
[
r
][
c
]
===
""
)
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
else
{
if
(
noirs
.
includes
(
board
[
r
][
c
]))
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
break
;
}
}
for
(
let
r
=
row
-
1
,
c
=
col
+
1
;
r
>=
0
&&
c
<
8
;
r
--
,
c
++
)
{
// Haut-Droite
if
(
board
[
r
][
c
]
===
""
)
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
else
{
if
(
noirs
.
includes
(
board
[
r
][
c
]))
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
break
;
}
}
for
(
let
r
=
row
+
1
,
c
=
col
-
1
;
r
<
8
&&
c
>=
0
;
r
++
,
c
--
)
{
// Bas-Gauche
if
(
board
[
r
][
c
]
===
""
)
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
else
{
if
(
noirs
.
includes
(
board
[
r
][
c
]))
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
break
;
}
}
for
(
let
r
=
row
+
1
,
c
=
col
+
1
;
r
<
8
&&
c
<
8
;
r
++
,
c
++
)
{
// Bas-Droite
if
(
board
[
r
][
c
]
===
""
)
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
else
{
if
(
noirs
.
includes
(
board
[
r
][
c
]))
{
moves
.
push
({
row
:
r
,
col
:
c
});
}
break
;
}
}
}
return
moves
;
}
...
...
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