Commit f8223c65 authored by Saad MAHBOUBI's avatar Saad MAHBOUBI
Browse files

saisir le message de validation pour vos modifications. Les lignes

parent 1a520eed
......@@ -34,6 +34,51 @@ export function emptyfile(chessboard : Chessboard, move: Move): boolean {
return i === end;
}
export function isEmptyFile(chessboard : Chessboard, move: Move): boolean{
let start: number ;
let end : number ;
if (move.from!.rank > move.to!.rank) {
start = move.to!.rank;
end = move.from!.rank;
} else {
end = move.to!.rank;
start = move.from!.rank;
}
for(let i : number = start + 1; i < end ; i = i + 1) {
let movePosition : Position = { rank : i , file : move.from!.file};
let squareMove : Square = squareAtPosition(chessboard, movePosition);
if(!squareMove.isEmpty){
return false;
}
}
return true;
}
export function isEmptyRank(chessboard : Chessboard, move: Move): boolean{
let start: number ;
let end : number ;
if (move.from!.file > move.to!.file) {
start = move.to!.file;
end = move.from!.file;
} else {
end = move.to!.file;
start = move.from!.file;
}
for(let i : number = start + 1; i < end ; i = i + 1) {
let movePosition : Position = { rank : move.from!.rank , file : i};
let squareMove : Square = squareAtPosition(chessboard, movePosition);
if(!squareMove.isEmpty){
return false;
}
}
return true;
}
export interface Square {
position : Position
isEmpty : boolean
......
import { Chessboard, isEmpty, Square, squareAtPosition } from "./chessboard";
import { Chessboard, isEmpty, Square, squareAtPosition, isEmptyFile, isEmptyRank } from "./chessboard";
import { Move } from "./movements";
import { equals, left, right, bottom, top } from "./position";
import * as pieces from './piece';
......@@ -191,11 +191,11 @@ export function rookMove(board: Chessboard, move: Move): boolean {
let depart: Square = squareAtPosition(board, move.from!);
let destination: Square = squareAtPosition(board, move.to!);
if (move.from!.rank === move.to!.rank ){
if (move.from!.rank === move.to!.rank && isEmptyRank(board, move)){
return isEmpty(board, move.to!) || depart.piece!.isWhite === !destination.piece!.isWhite ;
}
if (move.from!.file === move.to!.file ){
if (move.from!.file === move.to!.file && isEmptyFile(board, move)){
return isEmpty(board, move.to!) || depart.piece!.isWhite === !destination.piece!.isWhite ;
}
......
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