-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.java
More file actions
49 lines (40 loc) · 1.32 KB
/
Helper.java
File metadata and controls
49 lines (40 loc) · 1.32 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
public class Helper {
// char column -> int from 0 (with input check)
public static int column2int(char column) {
int temp = column;
int temp_integer = 97; // for lower case only: begin from 0
if (temp <= 105 && temp >= 97) {
return (temp - temp_integer);
} else {
throw new ArrayIndexOutOfBoundsException();
}
}
// String loc -> int[] both from 0
public static int[] getLocArray(String loc){
int i = column2int(loc.charAt(0));
int j = loc.charAt(1) - '1';
return new int[] {i,j};
}
// int, int -> String loc
public static String getLocStr(int col, int row){
char i = "abcdefgh".charAt(col);
char j = "12345678".charAt(row);
return (""+i+j);
}
// 'b/w' -> Color
public static Color getColor(char c) {
return switch (c) {
case 'b' -> Color.BLACK;
case 'w' -> Color.WHITE;
default -> throw new UnsupportedOperationException();
};
}
// print possible moves
public static void printMoves(Board b, String loc){
Piece p = b.getPiece(loc);
System.out.println("Possible moves of "+p.toString()+" at "+loc+": ");
for(String move: p.moves(b, loc)){
System.out.println(move);
}
}
}