Commit 09b03b19 authored by Romain DUPONT's avatar Romain DUPONT
Browse files

TODO avancé

parent b66d9863
......@@ -76,8 +76,9 @@ export function whitePawnMove(board: Chessboard, move: Move): boolean {
*/
export function kingMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
return (Math.abs(move.to!.rank - move.from!.rank) == 1 || Math.abs(move.to!.file - move.from!.file) == 1) && (isEmpty(board, move.to!) || isEatPossible(board, move));
return ((Math.abs(move.to!.rank - move.from!.rank) == 1 || Math.abs(move.to!.file - move.from!.file) == 1)
&& (isEmpty(board, move.to!) || isEatPossible(board, move))
&& !isDangerousCase(board,move.to!.rank,move.to!.file,pieceAtPosition(board, position(move.from!.file, move.from!.rank)).isWhite) );
}
/**
......@@ -118,8 +119,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 !isDangerousCase(board,move.to!.rank,move.to!.file, true )
return (DiagonalEmpty(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move));
}
/**
......@@ -387,86 +388,80 @@ function isDangerousCase(chessboard: Chessboard,rank:number,file:number,isWhite:
//-------------------------------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(file+1<8 && rank+2 < 8 && !isEmpty(chessboard,position(file+1,rank+2)) && isWhite != pieceAtPosition(chessboard, position(file+1,rank+2)).isWhite){
if(pieceAtPosition(chessboard, position(file+1,rank+2)).type == "Knight" ){
if(pieceAtPosition(chessboard, position(file+1,rank+2)).type == "Knight" ){
return true;
}
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(file+2<8 && rank+1 < 8 && !isEmpty(chessboard,position(file+2,rank+1)) && 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(file-1>0 && rank+2 < 8 && !isEmpty(chessboard,position(file-1,rank+2)) && 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(file-2>0 && rank+1 < 8 && !isEmpty(chessboard,position(file-2,rank+1)) && 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(file-1>0 && rank-2>0 && !isEmpty(chessboard,position(file-1,rank-2))&& 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(file-2>0 && rank-1>0 && !isEmpty(chessboard,position(file-2,rank-1)) && 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(file+1<8 && rank-2 >0 && !isEmpty(chessboard,position(file+1,rank-2)) && 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(file+2<8 && rank-1 > 0 && !isEmpty(chessboard,position(file+2,rank-1)) && isWhite != pieceAtPosition(chessboard, position(file+2,rank-1)).isWhite){
if(pieceAtPosition(chessboard, position(file+2,rank-1)).type == "Knight" ){
return true;
}
}
}
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