Commit 52f52e3c authored by Saad MAHBOUBI's avatar Saad MAHBOUBI 💬
Browse files
parents 554a7eed 13aa79f4
......@@ -37,6 +37,10 @@ class HttpServer {
res.end("var boardJSON= " + JSON.stringify(chessboard));
});
//app.post edit to show who's the turn.
//To do this we increment i (initialized to 0) of 1 each time a movement is validated.
//Otherwise we always show that the entered movement is invalid.
let i :number = 0 ;
app.post("/", (req: express.Request, res: express.Response) => {
......
......@@ -17,7 +17,7 @@ import * as pieces from './piece';
* @param move
*/
export function blackPawnMove(board: Chessboard, move: Move): boolean {
// #TODO: Manage special 'En passant' move.
if (equals(move.to!, top(move.from!))) {
//console.log("Single forward");
......@@ -75,8 +75,13 @@ export function whitePawnMove(board: Chessboard, move: Move): boolean {
* @param board The chessboard of the current game
* @param move
*/
//Conditional with the 8 moves of the knight,
//if the hit entered for the knight is included in one of these 8 moves
//then there is a check if the destination is empty or occupied by an opposing piece.
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!);
......@@ -117,7 +122,7 @@ export function kingMove(board: Chessboard, move: Move): boolean {
}
/**
/**
* Checks whether a Queen can perform a given move.
* The queen combines the power of a rook and bishop and can move any
* number of squares along a rank, file, or diagonal, but cannot leap over other pieces.
......@@ -125,6 +130,11 @@ export function kingMove(board: Chessboard, move: Move): boolean {
* @param board The chessboard of the current game
* @param move
*/
//one conditional for rank (use same structure as rookmove) or diagonal check (use same structure as bishopmove)
//other conditional for file (use same structure as rookmove) or "" ""
export function queenMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
......@@ -142,7 +152,7 @@ export function queenMove(board: Chessboard, move: Move): boolean {
return false;
}
/**
/**
* Checks whether a Rook can perform a given move.
* A rook can move any number of squares along a rank or file,
* but cannot leap over other pieces.
......@@ -150,8 +160,13 @@ export function queenMove(board: Chessboard, move: Move): boolean {
* @param board The chessboard of the current game
* @param move
*/
//check if the movement is a possible rook move (only file or rank move)
//then check box to box are empty and if the destination is empty or with an opponant piece.
export function rookMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
let depart: Square = squareAtPosition(board, move.from!);
let destination: Square = squareAtPosition(board, move.to!);
......@@ -167,7 +182,7 @@ export function rookMove(board: Chessboard, move: Move): boolean {
return false;
}
/**
/**
* Checks whether a Bishop can perform a given move.
* A bishop can move any number of squares diagonally,
* but cannot leap over other pieces.
......@@ -175,8 +190,11 @@ export function rookMove(board: Chessboard, move: Move): boolean {
* @param board The chessboard of the current game
* @param move
*/
/*check if the movement is a diagonal, then check box by box until the destination if there is no piece on the path
and for the destination box if it is empty or there is an opposing piece. */
export function bishopMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
let depart: Square = squareAtPosition(board, move.from!);
let destination: Square = squareAtPosition(board, move.to!);
......@@ -201,10 +219,14 @@ export function bishopMove(board: Chessboard, move: Move): boolean {
* @param move
*/
export function knightMove(board: Chessboard, move: Move): boolean {
// #TODO: Implement this function
let depart: Square = squareAtPosition(board, move.from!);
let destination: Square = squareAtPosition(board, move.to!);
//Conditional with the 8 moves of the knight,
//if the hit entered for the knight is included in one of these 8 moves
//then there is a check if the destination is empty or occupied by an opposing piece.
if (equals( move.to!, top(top(right(move.from!)))) ) {
return isEmpty(board, move.to!) || (depart.piece!.isWhite === !destination.piece!.isWhite);
}
......
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