-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnight.java
45 lines (29 loc) · 1.09 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
import java.awt.*;
import java.util.ArrayList;
public class Knight extends Piece{
public Knight(Location l, Image t, int c){
super(l,t,c);
}
public ArrayList<Location> getMoves(int[][] arr, Location loc){
ArrayList<Location> temp = new ArrayList<Location>();
int xPos = loc.getX();
int yPos = loc.getY();
if (new Location(xPos+1,yPos-2).isValidLoc())
temp.add(new Location(xPos+1,yPos-2));
if (new Location(xPos+2,yPos-1).isValidLoc())
temp.add(new Location(xPos+2,yPos-1));
if (new Location(xPos+2,yPos+1).isValidLoc())
temp.add(new Location(xPos+2,yPos+1));
if (new Location(xPos+1,yPos+2).isValidLoc())
temp.add(new Location(xPos+1,yPos+2));
if (new Location(xPos-1,yPos+2).isValidLoc())
temp.add(new Location(xPos-1,yPos+2));
if (new Location(xPos-2,yPos+1).isValidLoc())
temp.add(new Location(xPos-2,yPos+1));
if (new Location(xPos-2,yPos-1).isValidLoc())
temp.add(new Location(xPos-2,yPos-1));
if (new Location(xPos-1,yPos-2).isValidLoc())
temp.add(new Location(xPos-1,yPos-2));
return temp;
}
}