-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeState.java
48 lines (37 loc) · 1.02 KB
/
NodeState.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
public class NodeState {
public Pazzle current;
public NodeState former;
public int cost;
//初期値ありのコンストラクタ
NodeState(Pazzle pazzle){
current = pazzle;
current.hn = current.h2nCalc();
}
//初期値なしのコンストラクタ
NodeState(){
}
//cの数字と8を入れ替える関数
public Pazzle swap(int c){
Pazzle next = new Pazzle();
int i ;
for(i=0;i<9;i++){
next.coordinate.add(current.coordinate.get(i));
}
//8の座標を取得
int locateOf8 = next.coordinate.indexOf(8);
//8の場所にcの値を代入
next.coordinate.set(locateOf8, next.coordinate.get(c));
//cの場所に8を代入
next.coordinate.set(c, 8);
return next;
}
boolean goalCheck(){
int i;
for(i=0;i<8;i++){
if (current.coordinate.get(i) != i){
return false;
}
}
return true;
}
}