creation of framework of knightMoves, will add the conditions to not be
able to be on cases that are white
This commit is contained in:
parent
7b01772895
commit
7526532ea4
|
|
@ -252,17 +252,10 @@ public class Board {
|
|||
isAPieceHere = move.isRookMoveValid(x, y, color, selectX, selectY);
|
||||
|
||||
} else if (type == PieceType.Queen) {
|
||||
isAPieceHere = (move.isBishopMoveValid(x, y, color, selectX, selectY) || move.isRookMoveValid(x, y, color, selectX, selectY));
|
||||
isAPieceHere = (move.isBishopMoveValid(x, y, color, selectX, selectY) || move.isRookMoveValid(x, y, color, selectX, selectY)); // a queen is a Bishop and a rook, the move of both with an "Or" does the job !
|
||||
|
||||
} else if (type == PieceType.Knight) {
|
||||
|
||||
if(selectX == x+1 && selectY == y+2 || selectX == x-1 && selectY == y-2 ||
|
||||
selectX == x-1 && selectY == y+2 || selectX == x+1 && selectY == y-2 ||
|
||||
selectX == x+2 && selectY == y+1 || selectX == x-2 && selectY == y-1 ||
|
||||
selectX == x-2 && selectY == y+1 || selectX == x+2 && selectY == y-1 ) {
|
||||
isAPieceHere = true;
|
||||
|
||||
}
|
||||
isAPieceHere = move.isKnightMoveValid(x, y, color, selectX, selectY);
|
||||
|
||||
} else if (type == PieceType.King){
|
||||
for(int i = 1; i < 2;i++) {
|
||||
|
|
|
|||
|
|
@ -224,4 +224,49 @@ public class Move {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isKnightMoveValid(int x, int y, boolean color, int selectX, int selectY) {
|
||||
|
||||
if (selectX == x + 1 && selectY == y + 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectX == x - 1 && selectY == y - 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectX == x - 1 && selectY == y + 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectX == x + 1 && selectY == y - 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectX == x + 2 && selectY == y + 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectX == x - 2 && selectY == y - 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectX == x - 2 && selectY == y + 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectX == x + 2 && selectY == y - 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue