-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem.java
More file actions
47 lines (40 loc) · 1.16 KB
/
Problem.java
File metadata and controls
47 lines (40 loc) · 1.16 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
public class Problem {
public enum move{
Left, Right, Up, Down, Stay;
}
private move[][][] nexts = new move[][][]{
{{move.Right,move.Down,move.Stay},{move.Left,move.Right,move.Down,move.Stay},{move.Left,move.Down,move.Stay}},
{{move.Right,move.Up,move.Down,move.Stay},{move.Left,move.Right,move.Up,move.Down,move.Stay},{move.Left,move.Up,move.Down,move.Stay}},
{{move.Right,move.Up,move.Stay},{move.Left,move.Right,move.Up,move.Stay},{move.Left,move.Up,move.Stay}}
};
int[][] initial = new int[3][3];
int[][] data = new int[3][3];
public Problem(int[][] init) {
initial = init;
data = initial;
}
public Problem(Problem p) {
assignData(this.initial, p.initial);
assignData(this.data, p.initial);
}
public int[] getZIndex(){
for (int i = 0 ; i < 3; i++)
for(int j = 0 ; j < 3 ; j++){
if ( data[i][j] == 0){
return new int[]{i,j};
}
}
return null;
}
public move[] getNextMoves(){
int[] pos = getZIndex();
return nexts[pos[0]][pos[1]];
}
public void assignData(int[][] a,int[][] b){
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
a[i][j] = b[i][j];
}
}
}
}