Commit ca4255b3 authored by Teddy BARKOU's avatar Teddy BARKOU
Browse files

fonction isDangerousCase finie pour diagonales et horizontal

parent ac30d837
......@@ -118,7 +118,7 @@ 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))
}
/**
......@@ -136,9 +136,10 @@ export function bishopMove(board: Chessboard, move: Move): boolean {
export function knightMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
return (
/*return (
(((Math.abs(move.to!.rank - move.from!.rank) == 1 && Math.abs(move.to!.file - move.from!.file) == 2) ||
(Math.abs(move.to!.rank - move.from!.rank) == 2 && Math.abs(move.to!.file - move.from!.file) == 1))) && (isEmpty(board, move.to!) || isEatPossible(board, move)));
(Math.abs(move.to!.rank - move.from!.rank) == 2 && Math.abs(move.to!.file - move.from!.file) == 1))) && (isEmpty(board, move.to!) || isEatPossible(board, move)));*/
return !isDangerousCase(board,move.to!.rank,move.to!.file, true );
}
......@@ -241,14 +242,146 @@ function isEatPossible(chessboard: Chessboard, move: Move): boolean {
function isDangerousCase(chessboard: Chessboard,rank:number,file:number,isWhite:boolean ) : boolean{
let res = false;
for(let i: number=1; i<8-rank ; i++){
if(!isEmpty(chessboard,position(file,rank+i))){
if(isWhite != pieceAtPosition(chessboard, position(file,rank+i)).isWhite){
if(pieceAtPosition(chessboard, position(file,rank+i))){
if(pieceAtPosition(chessboard, position(file,rank+i)).type == "Queen"||
pieceAtPosition(chessboard, position(file,rank+i)).type == "Roock"||
(pieceAtPosition(chessboard, position(file,rank+i)).type == "King" && i==1)){
//TODO
return true;
}
}
break;
}
}
for(let i: number=1; i<rank ; i++){
if(!isEmpty(chessboard,position(file,rank-i))){
if(isWhite != pieceAtPosition(chessboard, position(file,rank-i)).isWhite){
if(pieceAtPosition(chessboard, position(file,rank-i)).type == "Queen"||
pieceAtPosition(chessboard, position(file,rank-i)).type == "Roock"||
(pieceAtPosition(chessboard, position(file,rank-i)).type == "King" && i==1)){
return true;
}
}
break;
}
}
for(let i: number=1; i<8-file ; i++){
if(!isEmpty(chessboard,position(file+i ,rank))){
if(isWhite != pieceAtPosition(chessboard, position(file+i,rank)).isWhite){
if(pieceAtPosition(chessboard, position(file+i,rank)).type == "Queen"||
pieceAtPosition(chessboard, position(file+i,rank)).type == "Roock"||
(pieceAtPosition(chessboard, position(file+i,rank)).type == "King" && i==1)){
return true;
}
}
break;
}
}
for(let i: number=1; i<file ; i++){
if(!isEmpty(chessboard,position(file-i,rank))){
if(isWhite != pieceAtPosition(chessboard, position(file-i,rank)).isWhite){
if(pieceAtPosition(chessboard, position(file-i,rank)).type == "Queen"||
pieceAtPosition(chessboard, position(file-i,rank)).type == "Roock"||
(pieceAtPosition(chessboard, position(file-i,rank)).type == "King" && i==1)){
return true;
}
}
break;
}
}
//-----------------------------------------VERIFICATION DIAGONALES-----------------------------------
for(let i: number=1; (i<8-file && i<8-rank) ; i++){
if(!isEmpty(chessboard,position(file+i,rank+i))){
if(isWhite != pieceAtPosition(chessboard, position(file+i,rank+i)).isWhite){
if(pieceAtPosition(chessboard, position(file+i,rank+i)).type == "Queen" ||
pieceAtPosition(chessboard, position(file+i,rank+i)).type == "Bishop" ||
(pieceAtPosition(chessboard, position(file+i,rank+i)).type == "King" && i==1) ||
(pieceAtPosition(chessboard, position(file+i,rank+i)).name == "Black Pawn" && i==1) ){
return true;
}
}
break;
}
}
for(let i: number=1; (i<8-file && i<rank) ; i++){
if(!isEmpty(chessboard,position(file+i,rank-i))){
if(isWhite != pieceAtPosition(chessboard, position(file+i,rank-i)).isWhite){
if(pieceAtPosition(chessboard, position(file+i,rank-i)).type == "Queen" ||
pieceAtPosition(chessboard, position(file+i,rank-i)).type == "Bishop" ||
(pieceAtPosition(chessboard, position(file+i,rank-i)).type == "King" && i==1) ||
(pieceAtPosition(chessboard, position(file+i,rank-i)).name == "White Pawn" && i==1) ){
return true;
}
}
break;
}
}
for(let i: number=1; (i<file && i<rank) ; i++){
if(!isEmpty(chessboard,position(file-i,rank-i))){
if(isWhite != pieceAtPosition(chessboard, position(file-i,rank-i)).isWhite){
if(pieceAtPosition(chessboard, position(file-i,rank-i)).type == "Queen" ||
pieceAtPosition(chessboard, position(file-i,rank-i)).type == "Bishop" ||
(pieceAtPosition(chessboard, position(file-i,rank-i)).type == "King" && i==1) ||
(pieceAtPosition(chessboard, position(file-i,rank-i)).name == "White Pawn" && i==1) ){
return true;
}
}
break;
}
}
for(let i: number=1; (i<file && i<8-rank) ; i++){
if(!isEmpty(chessboard,position(file-i,rank+i))){
if(isWhite != pieceAtPosition(chessboard, position(file-i,rank+i)).isWhite){
if(pieceAtPosition(chessboard, position(file-i,rank+i)).type == "Queen" ||
pieceAtPosition(chessboard, position(file-i,rank+i)).type == "Bishop" ||
(pieceAtPosition(chessboard, position(file-i,rank+i)).type == "King" && i==1) ||
(pieceAtPosition(chessboard, position(file-i,rank+i)).name == "Black Pawn" && i==1) ){
return true;
}
}
break;
}
}
return false;
}
\ No newline at end of file
......@@ -3,18 +3,19 @@ export interface Piece {
symbol : string,
isWhite : boolean,
name : string,
type : string,
}
export const whitePawn : Piece = {symbol : "", name: "White Pawn", isWhite : true};
export const whiteKing : Piece = {symbol : "", name: "White Pawn", isWhite : true};
export const whiteQueen : Piece = {symbol : "", name: "White Pawn", isWhite : true};
export const whiteRoock : Piece = {symbol : "", name: "White Pawn", isWhite : true};
export const whiteKnight : Piece = {symbol : "", name: "White Pawn", isWhite : true};
export const whiteBishop : Piece = {symbol : "", name: "White Pawn", isWhite : true};
export const whitePawn : Piece = {symbol : "", name: "White Pawn", isWhite : true, type : "Pawn"};
export const whiteKing : Piece = {symbol : "", name: "White Pawn", isWhite : true, type : "King"};
export const whiteQueen : Piece = {symbol : "", name: "White Pawn", isWhite : true, type : "Queen"};
export const whiteRoock : Piece = {symbol : "", name: "White Pawn", isWhite : true, type : "Roock"};
export const whiteKnight : Piece = {symbol : "", name: "White Pawn", isWhite : true, type : "Knight"};
export const whiteBishop : Piece = {symbol : "", name: "White Pawn", isWhite : true, type : "Bishop"};
export const blackPawn : Piece = {symbol : "", name: "Black Pawn", isWhite : false};
export const blackKing : Piece = {symbol : "", name: "Black Pawn", isWhite : false};
export const blackQueen : Piece = {symbol : "", name: "Black Pawn", isWhite : false};
export const blackRoock : Piece = {symbol : "", name: "Black Pawn", isWhite : false};
export const blackKnight : Piece = {symbol : "", name: "Black Pawn", isWhite : false};
export const blackBishop : Piece = {symbol : "", name: "Black Pawn", isWhite : false};
\ No newline at end of file
export const blackPawn : Piece = {symbol : "", name: "Black Pawn", isWhite : false, type : "Pawn"};
export const blackKing : Piece = {symbol : "", name: "Black Pawn", isWhite : false, type : "King"};
export const blackQueen : Piece = {symbol : "", name: "Black Pawn", isWhite : false, type : "Queen"};
export const blackRoock : Piece = {symbol : "", name: "Black Pawn", isWhite : false, type : "Roock"};
export const blackKnight : Piece = {symbol : "", name: "Black Pawn", isWhite : false, type : "Knight"};
export const blackBishop : Piece = {symbol : "", name: "Black Pawn", isWhite : false, type : "Bishop"};
\ 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