-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitializeState.java
90 lines (84 loc) · 2.33 KB
/
InitializeState.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
// import com.sun.org.apache.xml.internal.security.Init;
public class InitializeState {
public static final int COLS = 10;
public static final int ROWS = 21;
public static final int N_PIECES = 7;
//all legal moves - first index is piece type - then a list of 2-length arrays
protected static int[][][] legalMoves = new int[N_PIECES][][];
//indices for legalMoves
public static final int ORIENT = 0;
public static final int SLOT = 1;
//possible orientations for a given piece type
protected static int[] pOrients = {1,2,4,4,4,2,2};
//the next several arrays define the piece vocabulary in detail
//width of the pieces [piece ID][orientation]
protected static int[][] pWidth = {
{2},
{1,4},
{2,3,2,3},
{2,3,2,3},
{2,3,2,3},
{3,2},
{3,2}
};
//height of the pieces [piece ID][orientation]
private static int[][] pHeight = {
{2},
{4,1},
{3,2,3,2},
{3,2,3,2},
{3,2,3,2},
{2,3},
{2,3}
};
private static int[][][] pBottom = {
{{0,0}},
{{0},{0,0,0,0}},
{{0,0},{0,1,1},{2,0},{0,0,0}},
{{0,0},{0,0,0},{0,2},{1,1,0}},
{{0,1},{1,0,1},{1,0},{0,0,0}},
{{0,0,1},{1,0}},
{{1,0,0},{0,1}}
};
private static int[][][] pTop = {
{{2,2}},
{{4},{1,1,1,1}},
{{3,1},{2,2,2},{3,3},{1,1,2}},
{{1,3},{2,1,1},{3,3},{2,2,2}},
{{3,2},{2,2,2},{2,3},{1,2,1}},
{{1,2,2},{3,2}},
{{2,2,1},{2,3}}
};
public static void main(String[] args) {
//initialize legalMoves
//for each piece type
int numOfLegalMoves = 0;
for(int i = 0; i < N_PIECES; i++) {
//figure number of legal moves
System.out.println("Piece: " + (i+1) );
int n = 0;
for(int j = 0; j < pOrients[i]; j++) {
//number of locations in this orientation
n += COLS+1-pWidth[i][j];
}
System.out.println(" has orientations: " + pOrients[i] + " num of legal moves: " + n);
numOfLegalMoves = n;
//allocate space
legalMoves[i] = new int[n][2];
//for each orientation
n = 0;
for(int j = 0; j < pOrients[i]; j++) {
//for each slot
for(int k = 0; k < COLS+1-pWidth[i][j];k++) {
legalMoves[i][n][ORIENT] = j;
legalMoves[i][n][SLOT] = k;
n++;
}
}
for(int j=0; j<numOfLegalMoves; j++) {
System.out.println(" has legal move: " + (j+1) + " in orientation: " + (legalMoves[i][j][0]+1) + " in slot: " + (legalMoves[i][j][1]+1));
}
}
System.out.println("You have initialized everything!");
}
}