-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnight.java
37 lines (31 loc) · 1.17 KB
/
Knight.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class Knight extends Piece{
public Knight(int c, int y, int x){
if(c == 1){this.symbol = "♘";}
else{this.symbol = "♞";}
this.color = c;
this.currentX = x;
this.currentY = y;
}
public Piece[][] move(int y, int x, Piece[][] board, boolean ghost){
board = knightMove(board, y, x,-1, 2);
board = knightMove(board, y, x,1, 2);
board = knightMove(board, y, x,2, -1);
board = knightMove(board, y, x,2, 1);
board = knightMove(board, y, x,1, -2);
board = knightMove(board, y, x,-1, -2);
board = knightMove(board, y, x,-2, 1);
board = knightMove(board, y, x,-2, -1);
return board;
}
public Piece[][] knightMove(Piece[][] board, int y, int x, int changex, int changey){
if((currentX+changex == x && currentY+changey == y) || (currentX-1 == x && currentY+2 == y)){
if(board[y][x].getColor()!= color){
board[y][x] = board[currentY][currentX];
board[currentY][currentX] = new Piece();
currentX = x;
currentY = y;
}
}
return board;
}
}