-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKing.java
More file actions
75 lines (72 loc) · 1.64 KB
/
Copy pathKing.java
File metadata and controls
75 lines (72 loc) · 1.64 KB
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
import java.awt.Color;
import java.util.*;
/**
* Represents a king
* in chess.
*
* @author Linda Zeng
* @version 4.9.23
*/
public class King extends Piece
{
/**
* Constructs a king
* with given color and filename.
* It is valued at 1000.
*
* @param col color of king
* @param fileName file with image of king
*/
public King(Color col, String fileName)
{
super(col, fileName, 1000);
}
/**
* Indicates which locations
* the king can move to.
* It can move one away
* in all directions
*
* @return an ArrayList of
* locations this can
* move to
*/
public ArrayList<Location> destinations()
{
ArrayList<Location> res = new ArrayList<Location>();
Location cur = getLocation();
for (int i = cur.getRow() - 1; i <= cur.getRow() + 1; i++)
{
for (int j = cur.getCol() - 1; j <= cur.getCol() + 1; j++)
{
Location loc = new Location(i, j);
if (isValidDestination(loc))
{
res.add(loc);
}
}
}
return res;
}
/*private boolean willDie(Location l)
{
ArrayList<Move> other;
if (getColor() == Color.WHITE)
{
other = getBoard().allMoves(Color.BLACK);
}
else
{
other = getBoard().allMoves(Color.WHITE);
}
for (Move m: other)
{
if (m.getDestination().equals(l))
{
return true;
}
}
return false;
}
*/
}