Commit 11941203 authored by Maxime PERRIN's avatar Maxime PERRIN
Browse files

correction bug couleur peut manger l'autre couleur

parent f7e077df
......@@ -77,59 +77,91 @@ export function whitePawnMove(board: Chessboard, move: Move): boolean {
*/
export function kingMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
let depart: Square = squareAtPosition(board, move.from!);
let destination: Square = squareAtPosition(board, move.to!);
if (equals(move.to!, bottom(move.from!))) {
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
}
}
if (equals(move.to!, top(move.from!))) {
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
};
}
if (equals(move.to!, right(move.from!))) {
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
};
}
if (equals(move.to!, left(move.from!))) {
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
};
}
if(equals(move.to!, bottom(left(move.from!)))){
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
};
}
if(equals(move.to!, bottom(right(move.from!)))){
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
};
}
if(equals(move.to!, top(right(move.from!)))){
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
};
}
if(equals(move.to!, top(left(move.from!)))){
return isEmpty(board, move.to!);
if(isEmpty(board, move.to!)){
return true;
}else if(depart.piece!.isWhite === !destination.piece!.isWhite){
return true;
}else{
return false;
};
}
let start: Square = squareAtPosition(board, move.from!);
let destination: Square = squareAtPosition(board, move.to!);
if (start.piece!.isWhite == false && equals(move.to!, left(bottom(move.from!))) || equals(move.to!, right(bottom(move.from!))) || equals(move.to!, right(top(move.from!))) || equals(move.to!, left(top(move.from!))) ){
return !(destination.isEmpty || !destination.piece!.isWhite);
}
if (start.piece!.isWhite == false && equals(move.to!, left(move.from!)) || equals(move.to!, right(bottom(move.from!))) || equals(move.to!, top(move.from!)) || equals(move.to!, bottom(move.from!)) ){
return !(destination.isEmpty || !destination.piece!.isWhite);
}
if (start.piece!.isWhite == true && equals(move.to!, left(bottom(move.from!))) || equals(move.to!, right(bottom(move.from!))) || equals(move.to!, right(top(move.from!))) || equals(move.to!, left(top(move.from!))) ){
return !(destination.isEmpty || destination.piece!.isWhite);
}
if (start.piece!.isWhite == true && equals(move.to!, left(move.from!)) || equals(move.to!, right(bottom(move.from!))) || equals(move.to!, top(move.from!)) || equals(move.to!, bottom(move.from!)) ){
return !(destination.isEmpty || destination.piece!.isWhite);
}
return false;
}
/**
......
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