Nantes Université
Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
É
Échecs féeriques
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de conteneur
Registre de modèles
Opération
Environnements
Surveillance
Incidents
Service d'assistance
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Jessica RADAFY
Échecs féeriques
Validations
d425e686
Valider
d425e686
rédigé
il y a 5 ans
par
Enora LANGARD
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Mise à jour
parent
fa9dabcf
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/main/ts/move-validation.ts
+32
-12
32 ajouts, 12 suppressions
src/main/ts/move-validation.ts
avec
32 ajouts
et
12 suppressions
src/main/ts/move-validation.ts
+
32
−
12
Voir le fichier @
d425e686
...
...
@@ -3,7 +3,7 @@ import { Move } from "./movements";
import
{
equals
,
left
,
right
,
top
,
bottom
,
position
}
from
"
./position
"
;
/**
* Check that the
column
squares are empty or not
* Check that the
file
squares are empty or not
* @param chessboard
* @param move
*/
...
...
@@ -17,24 +17,25 @@ function isEmptyFile(chessboard : Chessboard, move : Move) : boolean {
return
false
;
}
if
(
move
.
from
!
.
rank
>
move
.
to
!
.
rank
)
{
//if the s
quare of origin > the
square
of
destination s
o
if
(
move
.
from
!
.
rank
>
move
.
to
!
.
rank
)
{
//if the s
tarting
square
> the
destination s
quare
start
=
move
.
to
!
.
rank
;
end
=
move
.
from
!
.
rank
;
}
else
{
end
=
move
.
to
!
.
rank
;
start
=
move
.
from
!
.
rank
;
}
let
i
:
number
=
start
+
1
;
while
(
i
<
end
&&
chessboard
.
board
[
file
][
i
].
isEmpty
)
{
let
i
:
number
=
start
+
1
;
// We only want to check the "middle" squares so we don't take in account the strating square
while
(
i
<
end
&&
chessboard
.
board
[
file
][
i
].
isEmpty
)
{
// Check if squares are empty
i
++
;
}
return
i
===
end
;
return
i
===
end
;
// Return this when there are not pieces on the way
}
/**
* Check the squares are empty or not
* Check the
rank
squares are empty or not
* @param chessboard
* @param move
*/
...
...
@@ -56,12 +57,12 @@ function isEmptyRank(chessboard : Chessboard, move: Move): boolean {
start
=
move
.
from
!
.
file
;
}
let
i
:
number
=
start
+
1
;
while
(
i
<
end
&&
chessboard
.
board
[
i
][
rank
].
isEmpty
)
{
let
i
:
number
=
start
+
1
;
// We only want to check the "middle" squares so we don't take in account the strating square
while
(
i
<
end
&&
chessboard
.
board
[
i
][
rank
].
isEmpty
)
{
// Check if squares are empty
i
++
;
}
return
i
===
end
;
return
i
===
end
;
// Return this when there are not pieces on the way
}
/**
...
...
@@ -161,12 +162,31 @@ export function kingMove(board: Chessboard, move: Move): boolean {
*/
export
function
queenMove
(
board
:
Chessboard
,
move
:
Move
):
boolean
{
let
destination
:
Square
=
squareAtPosition
(
board
,
move
.
to
!
);
let
start
:
Square
=
squareAtPosition
(
board
,
move
.
from
!
);
let
origin
:
Square
=
squareAtPosition
(
board
,
move
.
from
!
);
if
(
Math
.
abs
(
move
.
from
!
.
rank
-
move
.
to
!
.
rank
)
===
Math
.
abs
(
move
.
from
!
.
file
-
move
.
to
!
.
file
))
{
return
(
destination
.
isEmpty
||
destination
.
piece
!
.
isWhite
!==
start
.
piece
!
.
isWhite
);
return
(
destination
.
isEmpty
||
destination
.
piece
!
.
isWhite
!==
origin
.
piece
!
.
isWhite
);
}
// Validation of movement to move vertically
// Check that there is no pawn between origin square and the destination square
if
(
move
.
from
!
.
file
===
move
.
to
!
.
file
&&
isEmptyFile
(
board
,
move
)
==
true
)
{
// Check that "destination square is empty or the color of the piece that is on the origin square
// is different than the color of the piece which is on the destination square" is true
return
(
destination
.
isEmpty
||
destination
.
piece
!
.
isWhite
!==
origin
.
piece
!
.
isWhite
);
}
// Validation of movement to move horizontally
// Check that there is no pawn between origin square and the destination square
if
(
move
.
from
!
.
rank
===
move
.
to
!
.
rank
&&
isEmptyRank
(
board
,
move
)
==
true
)
{
// Check that "destination square is empty or the color of the piece that is on the origin square
// is different than the color of the piece which is on the destination square" is true
return
(
destination
.
isEmpty
||
destination
.
piece
!
.
isWhite
!==
origin
.
piece
!
.
isWhite
);
}
return
false
;
}
...
...
@@ -247,7 +267,7 @@ export function princessMove(board: Chessboard, move: Move): boolean {
return
(
destination
.
isEmpty
||
destination
.
piece
!
.
isWhite
!==
start
.
piece
!
.
isWhite
);
}
// Valdation of movement to move in "L"
// Val
i
dation of movement to move in "L"
if
(
equals
(
move
.
to
!
,
left
(
top
(
top
(
move
.
from
!
))))
||
equals
(
move
.
to
!
,
left
(
bottom
(
bottom
(
move
.
from
!
))))
||
equals
(
move
.
to
!
,
right
(
top
(
top
(
move
.
from
!
))))
||
...
...
This diff is collapsed.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter