Commit b66d9863 authored by Romain DUPONT's avatar Romain DUPONT
Browse files

add cavalier verif echec //TODO : réparer la fonction

parent aaf31994
......@@ -118,7 +118,8 @@ export function rookMove(board: Chessboard, move: Move): boolean {
*/
export function bishopMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this
return (DiagonalEmpty(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move))
//return (DiagonalEmpty(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move))
return !isDangerousCase(board,move.to!.rank,move.to!.file, true )
}
/**
......@@ -383,5 +384,89 @@ function isDangerousCase(chessboard: Chessboard,rank:number,file:number,isWhite:
break;
}
}
//-------------------------------Verification cavalier------------------------------------------
if(!isEmpty(chessboard,position(file,rank))){
if(file+1<9 && rank+2 < 9 && isWhite != pieceAtPosition(chessboard, position(file+1,rank+2)).isWhite){
if(pieceAtPosition(chessboard, position(file+1,rank+2)).type == "Knight" ){
return true;
}
}
}
if(!isEmpty(chessboard,position(file,rank))){
if(file+2<9 && rank+1 < 9 && isWhite != pieceAtPosition(chessboard, position(file+2,rank+1)).isWhite){
if(pieceAtPosition(chessboard, position(file+2,rank+1)).type == "Knight" ){
return true;
}
}
}
if(!isEmpty(chessboard,position(file,rank))){
if(file-1>0 && rank+2 < 9 && isWhite != pieceAtPosition(chessboard, position(file-1,rank+2)).isWhite){
if(pieceAtPosition(chessboard, position(file-1,rank+2)).type == "Knight" ){
return true;
}
}
}
if(!isEmpty(chessboard,position(file,rank))){
if(file-2>0 && rank+1 < 9 && isWhite != pieceAtPosition(chessboard, position(file-2,rank+1)).isWhite){
if(pieceAtPosition(chessboard, position(file-2,rank+1)).type == "Knight" ){
return true;
}
}
}
if(!isEmpty(chessboard,position(file,rank))){
if(file-1>0 && rank-2>0 && isWhite != pieceAtPosition(chessboard, position(file-1,rank-2)).isWhite){
if(pieceAtPosition(chessboard, position(file-1,rank-2)).type == "Knight" ){
return true;
}
}
}
if(!isEmpty(chessboard,position(file,rank))){
if(file-2>0 && rank-1>0 && isWhite != pieceAtPosition(chessboard, position(file-2,rank-1)).isWhite){
if(pieceAtPosition(chessboard, position(file-2,rank-1)).type == "Knight" ){
return true;
}
}
}
if(!isEmpty(chessboard,position(file,rank))){
if(file+1<9 && rank-2 >0 && isWhite != pieceAtPosition(chessboard, position(file+1,rank-2)).isWhite){
if(pieceAtPosition(chessboard, position(file+1,rank-2)).type == "Knight" ){
return true;
}
}
}
if(!isEmpty(chessboard,position(file,rank))){
if(file+2<9 && rank-1 < 9 && isWhite != pieceAtPosition(chessboard, position(file+2,rank-1)).isWhite){
if(pieceAtPosition(chessboard, position(file+2,rank-1)).type == "Knight" ){
return true;
}
}
}
return false;
}
\ No newline at end of file
}
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