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

changement du nom de la fonction

parent e10aca41
...@@ -76,7 +76,7 @@ export function whitePawnMove(board: Chessboard, move: Move): boolean { ...@@ -76,7 +76,7 @@ export function whitePawnMove(board: Chessboard, move: Move): boolean {
*/ */
export function kingMove(board: Chessboard, move: Move): boolean { export function kingMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function // #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));
} }
...@@ -90,7 +90,7 @@ export function kingMove(board: Chessboard, move: Move): boolean { ...@@ -90,7 +90,7 @@ export function kingMove(board: Chessboard, move: Move): boolean {
*/ */
export function queenMove(board: Chessboard, move: Move): boolean { export function queenMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function // #TODO: Implement this function
return (rankFileMove(board, move) || DiagonalMove(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move)); return (rankFileMove(board, move) || DiagonalEmpty(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move));
} }
/** /**
...@@ -104,7 +104,7 @@ export function queenMove(board: Chessboard, move: Move): boolean { ...@@ -104,7 +104,7 @@ export function queenMove(board: Chessboard, move: Move): boolean {
export function rookMove(board: Chessboard, move: Move): boolean { export function rookMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function // #TODO: Implement this function
return (rankFileMove(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move)); return (rankFileMove(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move));
} }
...@@ -118,7 +118,7 @@ export function rookMove(board: Chessboard, move: Move): boolean { ...@@ -118,7 +118,7 @@ export function rookMove(board: Chessboard, move: Move): boolean {
*/ */
export function bishopMove(board: Chessboard, move: Move): boolean { export function bishopMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this // #TODO: Implement this
return (DiagonalMove(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move)); return (DiagonalEmpty(board, move)) && (isEmpty(board, move.to!) || isEatPossible(board, move));
} }
/** /**
...@@ -138,8 +138,8 @@ export function knightMove(board: Chessboard, move: Move): boolean { ...@@ -138,8 +138,8 @@ export function knightMove(board: Chessboard, move: Move): boolean {
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) == 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)));
} }
...@@ -153,7 +153,7 @@ function rankFileMove(board: Chessboard, move: Move): boolean { ...@@ -153,7 +153,7 @@ function rankFileMove(board: Chessboard, move: Move): boolean {
} }
return true; return true;
} }
} else if (move.from!.rank < move.to!.rank){ } else if (move.from!.rank < move.to!.rank) {
if (move.from!.file === move.to!.file) { if (move.from!.file === move.to!.file) {
for (let i: number = move.from!.rank + 1; i < move.to!.rank; i++) { for (let i: number = move.from!.rank + 1; i < move.to!.rank; i++) {
if (!isEmpty(board, position(move.to!.file, i))) { if (!isEmpty(board, position(move.to!.file, i))) {
...@@ -164,7 +164,7 @@ function rankFileMove(board: Chessboard, move: Move): boolean { ...@@ -164,7 +164,7 @@ function rankFileMove(board: Chessboard, move: Move): boolean {
} }
return false; return false;
} else if (move.from!.file > move.to!.file) { } else if (move.from!.file > move.to!.file) {
if (move.from!.rank === move.to!.rank) { if (move.from!.rank === move.to!.rank) {
for (let i: number = move.from!.file - 1; i > move.to!.file; i--) { for (let i: number = move.from!.file - 1; i > move.to!.file; i--) {
if (!isEmpty(board, position(i, move.to!.rank))) { if (!isEmpty(board, position(i, move.to!.rank))) {
...@@ -173,7 +173,7 @@ function rankFileMove(board: Chessboard, move: Move): boolean { ...@@ -173,7 +173,7 @@ function rankFileMove(board: Chessboard, move: Move): boolean {
} }
return true; return true;
} }
} else if (move.from!.rank > move.to!.rank) { } else if (move.from!.rank > move.to!.rank) {
if (move.from!.file === move.to!.file) { if (move.from!.file === move.to!.file) {
for (let i: number = move.from!.rank - 1; i > move.to!.rank; i--) { for (let i: number = move.from!.rank - 1; i > move.to!.rank; i--) {
if (!isEmpty(board, position(move.to!.file, i))) { if (!isEmpty(board, position(move.to!.file, i))) {
...@@ -186,24 +186,24 @@ function rankFileMove(board: Chessboard, move: Move): boolean { ...@@ -186,24 +186,24 @@ function rankFileMove(board: Chessboard, move: Move): boolean {
return false; return false;
} }
} }
function DiagonalMove(board: Chessboard, move: Move): boolean { function DiagonalEmpty(board: Chessboard, move: Move): boolean {
if (Math.abs(move.to!.rank - move.from!.rank) == Math.abs(move.to!.file - move.from!.file)) { // is diagonal ? if (Math.abs(move.to!.rank - move.from!.rank) == Math.abs(move.to!.file - move.from!.file)) { // is diagonal ?
if (move.to!.rank - move.from!.rank > 0 && move.to!.file - move.from!.file > 0) { // est la diagonale haut droite if (move.to!.rank - move.from!.rank > 0 && move.to!.file - move.from!.file > 0) { // est la diagonale haut droite
for (let n: number = 1; n < (move.to!.rank - move.from!.rank) ; n++) { for (let n: number = 1; n < (move.to!.rank - move.from!.rank); n++) {
if (!isEmpty(board, position(move.from!.file + n, move.from!.rank + n))) { if (!isEmpty(board, position(move.from!.file + n, move.from!.rank + n))) {
return false; return false;
} }
} }
return true; return true;
} else if (move.to!.file - move.from!.file > 0) { // est la diagonale haut gauche } else if (move.to!.file - move.from!.file > 0) { // est la diagonale haut gauche
for (let n: number = 1; n < (move.to!.file - move.from!.file) ; n++) { for (let n: number = 1; n < (move.to!.file - move.from!.file); n++) {
if (!isEmpty(board, position(move.from!.file + n, move.from!.rank - n))) { if (!isEmpty(board, position(move.from!.file + n, move.from!.rank - n))) {
return false; return false;
} }
...@@ -211,14 +211,14 @@ function DiagonalMove(board: Chessboard, move: Move): boolean { ...@@ -211,14 +211,14 @@ function DiagonalMove(board: Chessboard, move: Move): boolean {
return true; return true;
} else if (move.to!.rank - move.from!.rank > 0) { // est la diagonale bas droite } else if (move.to!.rank - move.from!.rank > 0) { // est la diagonale bas droite
for (let n: number = 1; n < (move.to!.rank - move.from!.rank) ; n++) { for (let n: number = 1; n < (move.to!.rank - move.from!.rank); n++) {
if (!isEmpty(board, position(move.from!.file - n, move.from!.rank + n))) { if (!isEmpty(board, position(move.from!.file - n, move.from!.rank + n))) {
return false; return false;
} }
} }
return true; return true;
} }
else { // est la diagonale haut gauche else { // est la diagonale haut gauche
for (let n: number = 1; n < (move.from!.file - move.to!.file); n++) { //est la diagonale bas gauche for (let n: number = 1; n < (move.from!.file - move.to!.file); n++) { //est la diagonale bas gauche
if (!isEmpty(board, position(move.from!.file - n, move.from!.rank - n))) { if (!isEmpty(board, position(move.from!.file - n, move.from!.rank - n))) {
...@@ -230,10 +230,12 @@ function DiagonalMove(board: Chessboard, move: Move): boolean { ...@@ -230,10 +230,12 @@ function DiagonalMove(board: Chessboard, move: Move): boolean {
return true; return true;
} }
} return false ; } return false;
} }
function isEatPossible(chessboard: Chessboard, move : Move):boolean { function isEatPossible(chessboard: Chessboard, move: Move): boolean {
return ((pieceAtPosition(chessboard, position(move.from!.file, move.from!.rank)).isWhite) != (pieceAtPosition(chessboard, position(move.to!.file, move.to!.rank)).isWhite));
}
return( (pieceAtPosition(chessboard,position(move.from!.file, move.from!.rank)).isWhite) != (pieceAtPosition(chessboard,position(move.to!.file, move.to!.rank)).isWhite)); //function isKingInEchec
} \ No newline at end of file
\ 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