-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathColor.java
More file actions
47 lines (36 loc) · 982 Bytes
/
Color.java
File metadata and controls
47 lines (36 loc) · 982 Bytes
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
package chess;
import java.util.Arrays;
import java.util.List;
public enum Color {
BLACK(new Position(Column.A, Row.SEVEN)),
WHITE(new Position(Column.A, Row.ONE)),
EMPTY(null);
private final Position firstPawnPosition;
Color(Position firstPawnPosition) {
this.firstPawnPosition = firstPawnPosition;
}
public static List<Color> validColors() {
return Arrays.stream(Color.values())
.filter(color -> !color.isEmpty())
.toList();
}
public boolean isWhite() {
return this == WHITE;
}
public boolean isBlack() {
return this == BLACK;
}
public boolean isEmpty() {
return this == EMPTY;
}
public Color opposite() {
return switch (this) {
case BLACK -> WHITE;
case WHITE -> BLACK;
default -> EMPTY;
};
}
public Position getFirstPawnPosition() {
return firstPawnPosition;
}
}