This repository has been archived by the owner on May 17, 2023. It is now read-only.
forked from ahmadnaufal/aimaze-ev3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGBFS.c
134 lines (123 loc) · 2.62 KB
/
GBFS.c
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
int finish;
int persimpangan;
int buntu;
//way: 1 = utara, 2 = timur, 3 = selatan, 4 = barat
int *savedWay;
int curretWay=1;
string currentColor="black";
typedef struct {
int way;
string color;
} direction;
int n=0;
direction nextDirection;
direction *dirOpsion;
int GBFS() {
if(finish) {
return 1;
} else {
if(persimpangan) {
savedWay[n]=curretWay;
n++;
nextWay=chooseDirection().way;
if(goTo(nextWay)){;
return GBFS();
}
} else {
if (buntu) {
if(backToPreviousNode()){
return GBFS();
}
}
}
}
}
string chooseDirection() {
direction next;
inputDirection(dirOpsion);
next = chooseShortestPath(dirOpsion);
return next;
}
int backToPreviousNode(){
int nextWay=turnBack(curretWay);
curretWay=goAhead(nextWay);
return 1;
}
void inputDirection(direction *dirOpsion){
int way;
i=0;
way=forward(curretWay);
if(currentColor!="white"){
*dirOpsion[i].way=curretWay;
*dirOpsion[i].color=currentColor;
i++;
}
way=back(way);
way=turnRight(way);
if(currentColor!="white"){
*dirOpsion[i].way=curretWay;
*dirOpsion[i].color=currentColor;
i++;
}
way=backRight(way);
way=turnLeft(way);
if(currentColor!="white"){
*dirOpsion[i].way=curretWay;
*dirOpsion[i].color=currentColor;
i++;
}
way=backLeft(way);
}
int goTo(int nextWay){
switch (curretWay) {
case 1:{
if(nextWay==1){
curretWay=goAhead(curretWay);
} else if(nextWay==2){
curretWay=turnRight(curretWay)
curretWay=goAhead(curretWay);
}else if(nextWay==4){
curretWay=turnLeft(curretWay)
curretWay=goAhead(curretWay);
}
break;
}
case 2:{
if(nextWay==2){
curretWay=goAhead(curretWay);
} else if(nextWay==3){
curretWay=turnRight(curretWay)
curretWay=goAhead(curretWay);
}else if(nextWay==1){
curretWay=turnLeft(curretWay)
curretWay=goAhead(curretWay);
}
break;
}
case 3:{
if(nextWay==3){
curretWay=goAhead(curretWay);
} else if(nextWay==4){
curretWay=turnRight(curretWay)
curretWay=goAhead(curretWay);
}else if(nextWay==2){
curretWay=turnLeft(curretWay)
curretWay=goAhead(curretWay);
}
break;
}
case 4:{
if(nextWay==4){
curretWay=goAhead(curretWay);
} else if(nextWay==1){
curretWay=turnRight(curretWay)
curretWay=goAhead(curretWay);
}else if(nextWay==3){
curretWay=turnLeft(curretWay)
curretWay=goAhead(curretWay);
}
break;
}
}
return 1;
}