-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGGNode.java
78 lines (67 loc) · 1.41 KB
/
GGNode.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
package DrNim;
public class GGNode { //node in a GraphGame
GGNode[] successors;
int sg; //the SG-vale of this node. -1 means not labeled yet
int number; //1 based counting
public GGNode(){
successors=new GGNode[0];
}
public void calcSG(){ //complexity: O(#this.successors^2)
int k=0;
if(successors.length==0){
//do nothing
}else{
boolean loop=true;
while(loop){
for(int i=0;i<successors.length;i++){
if(k==successors[i].getSG()){
k++;
loop=true;
break;
}else{
loop=false;;
}
}
}//end while(loop)
}
sg=k;
}
public int getSG() {
return sg;
}
public void addSuc(GGNode suc){
if(isAlreadyIn(suc.getNumber())){
//do nothing
}else{
GGNode[] z=new GGNode[successors.length+1];
for(int i=0;i<successors.length;i++){
z[i]=successors[i];
}
z[successors.length]=suc;
successors=z;
}
}
private int getNumber() {
return number;
}
public boolean isAlreadyIn(int num) { //returns true iff this GGNode has a successor with number=='num'
boolean b=false;
if(successors.length==0){
//do nothing
}else{
for(int i=0;i<successors.length;i++){
if(successors[i].getNumber()==num){
b=true;
break;
}
}
}
return b;
}
public void setNumber(int i) {
number=i;
}
public void setSG(int i) {
sg=i;
}
}