Commit 9a3a5982 authored by Saad MAHBOUBI's avatar Saad MAHBOUBI
Browse files

fin de du projet, tout fonction plus qu'a simplifier quelque fonction et

ajouter quelque commentaire pour les fonction et enlever quelque TODO
parent 2dbd3d82
......@@ -394,7 +394,6 @@ describe("Test bishopMove()", () => {
let diagonalForwardLeftMove = {from: positionE4, to: positionA8, isValid: true};
expect(isPossible.bishopMove(chessboard,diagonalForwardLeftMove )).toBeTruthy();
//FIXE ME: erreur de test expect false to be truthy , alors que si un prend la case G6 (la case diagonal d'avant) l'erreur disparait
let diagonalForwardRightMove = {from: positionE4, to: positionH7, isValid: true};
expect(isPossible.bishopMove(chessboard,diagonalForwardRightMove )).toBeTruthy();
......@@ -649,4 +648,23 @@ describe("Test rookMove()", () => {
let cannotCapture: Move = {from: positionE4, to: positionH4, isValid: true}
expect(isPossible.rookMove(chessboard, cannotCapture)).toBeFalsy();
});
});
describe("Test bishopMove()", () => {
beforeEach( () => {
// TODO:
// Initialize an empty chessboard
chessboard = createEmptyChessboard();
// Place a black Bishop on E4
putPiece(chessboard, positionE4, pieces.blackBishop);
});
it("A Bishop can move diagonally", () => {
// TODO:
// Check the following moves are possible:
//FIXE ME: erreur de test expect false to be truthy , alors que si un prend la case G6 (la case diagonal d'avant) l'erreur disparait
let diagonalForwardRightMove = {from: positionE4, to: positionH7, isValid: true};
expect(isEmptyDiagonal(chessboard,diagonalForwardRightMove )).toBeTruthy();
});
});
\ No newline at end of file
......@@ -80,51 +80,60 @@ export function isEmptyRank(chessboard : Chessboard, move: Move): boolean{
}
export function isEmptyDiagonal(chessboard : Chessboard, move: Move): boolean{
let moveFile : number ;
let moveRank : number ;
let i : number;
let j : number
if(move.from!.file > move.to!.file && move.from!.rank > move.to!.rank){
i = move.from!.rank - 1;
j = move.from!.file - 1;
while((i > move.to!.rank) && (j > move.to!.file) && chessboard.board[i][j].isEmpty){
i--;
j--;
for(let i : number = move.from!.rank - 2; i > move.to!.rank + 1; i--) {
for(let j : number = move.from!.file - 2; j > move.to!.file + 1; j--) {
let movePosition: Position = {rank : i, file : j};
let squareMove : Square = squareAtPosition(chessboard, movePosition);
if(!squareMove.isEmpty){
return false;
}
}
}
}else if(move.from!.file > move.to!.file && move.from!.rank < move.to!.rank){
i = move.from!.rank + 1;
j = move.from!.file - 1;
while((i < move.to!.rank) && (j > move.to!.file) && chessboard.board[i][j].isEmpty){
i++;
j--;
for(let i : number = move.from!.rank + 2; i < move.to!.rank - 1; i++) {
for(let j : number = move.from!.file - 2; j > move.to!.file + 1; j--) {
let movePosition: Position = {rank : i, file : j};
let squareMove : Square = squareAtPosition(chessboard, movePosition);
if(!squareMove.isEmpty){
return false;
}
}
}
}else if(move.from!.file < move.to!.file && move.from!.rank > move.to!.rank){
i = move.from!.rank - 1;
j = move.from!.file + 1;
while((i > move.to!.rank) && (j < move.to!.file) && chessboard.board[i][j].isEmpty){
i--;
j++;
for(let i : number = move.from!.rank - 2; i < move.to!.rank + 1; i--) {
for(let j : number = move.from!.file + 2; j < move.to!.file - 1; j++) {
let movePosition: Position = {rank : i, file : j};
let squareMove : Square = squareAtPosition(chessboard, movePosition);
if(!squareMove.isEmpty){
return false;
}
}
}
}else{
i = move.from!.rank + 1;
j = move.from!.file + 1;
while((i < move.to!.rank) && (j < move.to!.file) && chessboard.board[i][j].isEmpty){
i++;
j++;
for(let i : number = move.from!.rank + 2; i < move.to!.rank - 1; i++) {
for(let j : number = move.from!.file + 2; j < move.to!.file - 1; j++) {
let movePosition: Position = {rank : i, file : j};
let squareMove : Square = squareAtPosition(chessboard, movePosition);
if(!squareMove.isEmpty){
return false;
}
}
}
}
if(!(Math.abs(move.from!.file - move.to!.file) === Math.abs(move.from!.rank - move.to!.rank))){
return false;
}
/*let movePosition : Position = {rank : i, file : j};
let squareMove : Square = squareAtPosition(chessboard, movePosition);*/
return (i === (move.to!.file ) && (j === (move.to!.rank )));
return true;
}
export interface Square {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment