Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider adea0437 rédigé par Stewan Lheureux's avatar Stewan Lheureux
Parcourir les fichiers

Ajout de fonctions

parent 2d306101
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -120,7 +120,7 @@ export function queenMove(board: Chessboard, move: Move): boolean {
*/
export function empressMove(board: Chessboard, move: Move): boolean {
/* Comme la Tour mais avec en plus les mouvements du chevalier */
/*
// Mouvements du Chevalier
// Mouvement vers le bas
......@@ -143,21 +143,21 @@ export function empressMove(board: Chessboard, move: Move): boolean {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move))
}
*/
// Mouvements de la Tour haut et bas
if (move.from!.file == move.to!.file) { // Le déplacement se fait-il sur la même colonne ?
let moveRange = Math.abs(move.from!.file-move.to!.file!); // combien de cases on veut traverser ?
let moveRange = Math.abs(move.from!.rank-move.to!.rank!); // combien de cases on veut traverser en haut ou en bas ?
let moveFromTop = move.from!;
let moveFromBottom = move.from!;
for (let i=1; i<=moveRange; i++) {
// Si on va en haut
if (move.from!.file!-move.to!.file! < 0) {
if (move.from!.rank!-move.to!.rank! < 0) {
if (equals(move.to!, top(move.from!))) {
if (equals(move.to!, top(moveFromTop))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
......@@ -168,13 +168,75 @@ export function empressMove(board: Chessboard, move: Move): boolean {
return false;
}
}
}
// Si on va en bas
if (move.from!.rank!-move.to!.rank! > 0) {
moveFromTop = top(moveFromTop);
if (equals(move.to!, bottom(moveFromBottom))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
}
else {
let destination: Square = squareAtPosition(board, bottom(moveFromBottom));
if (!destination.isEmpty) {
return false;
}
}
}
moveFromTop = top(moveFromTop);
moveFromBottom = bottom(moveFromBottom);
}
}
if (move.from!.rank == move.to!.rank) { // Le déplacement se fait-il sur la même ligne ?
let moveRange = Math.abs(move.from!.file-move.to!.file!); // combien de cases on veut traverser à gauche ou à droite ?
let moveFromRight = move.from!;
let moveFromLeft = move.from!;
for (let i=1; i<=moveRange; i++) {
// Si on va à droite
if (move.from!.file!-move.to!.file! < 0) {
if (equals(move.to!, right(moveFromRight))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
else {
let destination: Square = squareAtPosition(board, right(moveFromRight));
if (!destination.isEmpty) {
return false;
}
}
}
// Si on va à gauche
if (move.from!.file!-move.to!.file! > 0) {
if (equals(move.to!, left(moveFromLeft))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
else {
let destination: Square = squareAtPosition(board, left(moveFromLeft));
if (!destination.isEmpty) {
return false;
}
}
}
moveFromRight = right(moveFromRight);
moveFromLeft = left(moveFromLeft);
}
}
return false;
}
......@@ -191,8 +253,97 @@ export function empressMove(board: Chessboard, move: Move): boolean {
* @param move
*/
export function princessMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
return true;
// Mouvements du Fou
if (Math.abs(move.to!.rank - move.from!.rank) == Math.abs(move.to!.file - move.from!.file)) {
let moveRange = Math.abs(move.from!.rank-move.to!.rank);
let moveFrom11pm = move.from!;
let moveFrom8pm = move.from!;
let moveFrom5pm = move.from!;
let moveFrom2pm = move.from!;
for (let i=1; i<=moveRange; i++) {
// Si on va en haut à gauche (11pm)
if (move.to!.file > move.from!.file && move.to!.rank < move.from!.rank) {
if (equals(move.to!, left(top(moveFrom11pm)))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
else {
let destination: Square = squareAtPosition(board, left(top(moveFrom11pm)));
if (!destination.isEmpty) {
return false;
}
}
}
// Si on va en haut à droite (2pm)
if (move.to!.file > move.from!.file && move.to!.rank > move.from!.rank) {
if (equals(move.to!, right(top(moveFrom2pm)))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
else {
let destination: Square = squareAtPosition(board, right(top(moveFrom2pm)));
if (!destination.isEmpty) {
return false;
}
}
}
// Si on va en bas à gauche (8pm)
if (move.to!.file < move.from!.file && move.to!.rank < move.from!.rank) {
if (equals(move.to!, left(bottom(moveFrom8pm)))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
else {
let destination: Square = squareAtPosition(board, left(bottom(moveFrom8pm)));
if (!destination.isEmpty) {
return false;
}
}
}
// Si on va en bas à droite (5pm)
if (move.to!.file < move.from!.file && move.to!.rank > move.from!.rank) {
if (equals(move.to!, right(bottom(moveFrom5pm)))) {
let destination: Square = squareAtPosition(board, move.to!);
return (destination.isEmpty || isValidEat(board,move));
}
else {
let destination: Square = squareAtPosition(board, right(bottom(moveFrom5pm)));
if (!destination.isEmpty) {
return false;
}
}
}
moveFrom11pm = left(top(moveFrom11pm));
moveFrom8pm = left(bottom(moveFrom8pm));
moveFrom5pm = right(bottom(moveFrom5pm));
moveFrom2pm = right(top(moveFrom2pm));
}
}
return false;
}
/**
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter