Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider d425e686 rédigé par Enora LANGARD's avatar Enora LANGARD
Parcourir les fichiers

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
......@@ -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 square of origin > the square of destination so
if (move.from!.rank > move.to!.rank) { //if the starting square > the destination square
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"
// Validation 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!)))) ||
......
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