-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnight.java
106 lines (90 loc) · 1.97 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
public class Knight extends Piece {
public int value;
public Knight(int turn, int xloc, int yloc, String piece_name, int score) {
super(turn,xloc,yloc,piece_name, score);
}
public int get_value(int turn) {
if(turn == 1) {
value = -30;
}
else if(turn == 0) {
value = 30;
}
return value;
}
@Override
public ArrayList<int[]> get_moves(Piece[][] board) {
ArrayList<int[]> moves = new ArrayList<int[]>();
int[] move = new int[2];
if(x+1<8 &&y-2>=0) {
if(board[x+1][y-2].get_team()!=team) {
move[0] = x+1;
move[1] = y-2;
moves.add(move);
}
}
move = new int[2];
if(x+1<8 &&y+2<8)
if(board[x+1][y+2].get_team()!=team) {
move[0] = x+1;
move[1] = y+2;
moves.add(move);
}
move = new int[2];
if(x-1>=0 &&y+2<8)
if(board[x-1][y+2].get_team()!=team) {
move[0] = x-1;
move[1] = y+2;
moves.add(move);
}
move = new int[2];
if(x-1>=0 &&y-2>=0)
if(board[x-1][y-2].get_team()!=team) {
move[0] = x-1;
move[1] = y-2;
moves.add(move);
}
move = new int[2];
if(x+2<8&&y-1>=0)
if(board[x+2][y-1].get_team()!=team) {
move[0] = x+2;
move[1] = y-1;
moves.add(move);
}
move = new int[2];
if(x+2<8 &&y+1<8)
if(board[x+2][y+1].get_team()!=team) {
move[0] = x+2;
move[1] = y+1;
moves.add(move);
}
move = new int[2];
if(x-2>=0&&y+1<8)
if(board[x-2][y+1].get_team()!=team) {
move[0] = x-2;
move[1] = y+1;
moves.add(move);
}
move = new int[2];
if(x-2>=0&&y-1>=0)
if(board[x-2][y-1].get_team()!=team) {
move[0] = x-2;
move[1] = y-1;
moves.add(move);
}
return moves;
}
@Override
public boolean check(King king, Piece[][] board) {
int x_dist = king.get_loc()[0] - x;
int y_dist = king.get_loc()[1] - y;
if (Math.abs(x_dist) == 2 && Math.abs(y_dist) == 1)
return true;
else if (Math.abs(x_dist) == 1 && Math.abs(y_dist) == 2)
return true;
return false;
}
}