5
5
6
6
import datatypes .Movement ;
7
7
import datatypes .Orientation ;
8
+ import main .RobotSystem ;
8
9
import simulator .arena .Arena ;
9
10
import simulator .robot .Robot ;
10
11
@@ -123,7 +124,11 @@ private void init(int[][] mazeRef) {
123
124
_robot = Robot .getInstance ();
124
125
}
125
126
126
- public Orientation moveRobotAlongFastestPath (Path fastestPath , Orientation currentOrientation , boolean isExploring ) {
127
+ public Orientation moveRobotAlongFastestPath (Path fastestPath , Orientation currentOrientation ) {
128
+ return moveRobotAlongFastestPath (fastestPath , currentOrientation , false , false );
129
+ }
130
+
131
+ public Orientation moveRobotAlongFastestPath (Path fastestPath , Orientation currentOrientation , boolean isExploring , boolean hasCalibration ) {
127
132
128
133
int [] tempPosition = new int [2 ];
129
134
int [] robotPosition ;
@@ -135,7 +140,7 @@ public Orientation moveRobotAlongFastestPath(Path fastestPath, Orientation curre
135
140
robotPosition = fastestPath .getStep (0 );
136
141
137
142
int count = 0 ;
138
-
143
+
139
144
for (int i = 0 ; i < steps .size () - 1 ; i ++) {
140
145
141
146
tempPosition [0 ] = steps .get (i ).getX ();
@@ -152,37 +157,25 @@ public Orientation moveRobotAlongFastestPath(Path fastestPath, Orientation curre
152
157
153
158
if (isExploring ) {
154
159
for (int v = 0 ; v < count ; v ++) {
155
- robotPosition = explorer .updateRobotPositionAfterMF (currentOrientation , robotPosition );
156
- explorer .setIsExplored (robotPosition , currentOrientation );
157
160
_robot .moveForward ();
161
+ robotPosition = explorer .updateRobotPositionAfterMF (currentOrientation , robotPosition );
162
+ explorer .setIsExplored (robotPosition , currentOrientation , hasCalibration );
158
163
}
159
164
} else {
160
165
_robot .moveForward (count );
161
166
}
162
167
count = 1 ;
163
- Movement move = ChangeRobotOrientation (currentOrientation , nextOrientation );
164
- Orientation ori ;
165
- if (isExploring ) {
166
- if (move == Movement .TURN_RIGHT_TWICE ) {
167
- ori = explorer .updateRobotOrientation (Movement .TURN_RIGHT );
168
- explorer .setIsExplored (robotPosition , ori );
169
- explorer .updateRobotOrientation (Movement .TURN_RIGHT );
170
- explorer .setIsExplored (robotPosition , ori );
171
- } else {
172
- ori = explorer .updateRobotOrientation (move );
173
- explorer .setIsExplored (robotPosition , ori );
174
- }
175
- }
168
+ ChangeRobotOrientation (currentOrientation , nextOrientation , isExploring , hasCalibration );
176
169
}
177
170
currentOrientation = nextOrientation ;
178
171
}
179
172
180
173
181
174
if (isExploring ) {
182
175
for (int v = 0 ; v < count ; v ++) {
183
- robotPosition = explorer .updateRobotPositionAfterMF (currentOrientation , robotPosition );
184
- explorer .setIsExplored (robotPosition , currentOrientation );
185
176
_robot .moveForward ();
177
+ robotPosition = explorer .updateRobotPositionAfterMF (currentOrientation , robotPosition );
178
+ explorer .setIsExplored (robotPosition , currentOrientation , hasCalibration );
186
179
}
187
180
} else {
188
181
_robot .moveForward (count );
@@ -194,61 +187,110 @@ public Orientation moveRobotAlongFastestPath(Path fastestPath, Orientation curre
194
187
195
188
196
189
197
- private Movement ChangeRobotOrientation (Orientation curOri , Orientation nextOri ) {
190
+ private void ChangeRobotOrientation (Orientation curOri , Orientation nextOri , boolean isExploring , boolean hasCalibration ) {
191
+ MazeExplorer explorer = MazeExplorer .getInstance ();
192
+
198
193
switch (curOri ) {
199
194
case NORTH :
200
195
if (nextOri == Orientation .EAST ) {
201
196
_robot .turnRight ();
202
- return Movement .TURN_RIGHT ;
197
+ if (isExploring ) {
198
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
199
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
200
+ }
203
201
} else if (nextOri == Orientation .WEST ) {
204
202
_robot .turnLeft ();
205
- return Movement .TURN_LEFT ;
203
+ if (isExploring ) {
204
+ explorer .updateRobotOrientation (Movement .TURN_LEFT );
205
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
206
+ }
206
207
} else if (nextOri == Orientation .SOUTH ) {
207
208
_robot .turnRight ();
209
+ if (isExploring ) {
210
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
211
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
212
+ }
208
213
_robot .turnRight ();
209
- return Movement .TURN_RIGHT_TWICE ;
214
+ if (isExploring ) {
215
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
216
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
217
+ }
210
218
}
211
219
break ;
212
220
case SOUTH :
213
221
if (nextOri == Orientation .EAST ) {
214
222
_robot .turnLeft ();
215
- return Movement .TURN_LEFT ;
223
+ if (isExploring ) {
224
+ explorer .updateRobotOrientation (Movement .TURN_LEFT );
225
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
226
+ }
216
227
} else if (nextOri == Orientation .WEST ) {
217
228
_robot .turnRight ();
218
- return Movement .TURN_RIGHT ;
229
+ if (isExploring ) {
230
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
231
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
232
+ }
219
233
} else if (nextOri == Orientation .NORTH ) {
220
234
_robot .turnRight ();
235
+ if (isExploring ) {
236
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
237
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
238
+ }
221
239
_robot .turnRight ();
222
- return Movement .TURN_RIGHT_TWICE ;
240
+ if (isExploring ) {
241
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
242
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
243
+ }
223
244
}
224
245
break ;
225
246
case EAST :
226
247
if (nextOri == Orientation .NORTH ) {
227
248
_robot .turnLeft ();
228
- return Movement .TURN_LEFT ;
249
+ if (isExploring ) {
250
+ explorer .updateRobotOrientation (Movement .TURN_LEFT );
251
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
252
+ }
229
253
} else if (nextOri == Orientation .SOUTH ) {
230
254
_robot .turnRight ();
231
- return Movement .TURN_RIGHT ;
255
+ if (isExploring ) {
256
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
257
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
258
+ }
232
259
} else if (nextOri == Orientation .WEST ) {
233
260
_robot .turnRight ();
261
+ if (isExploring ) {
262
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
263
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
264
+ }
234
265
_robot .turnRight ();
235
- return Movement .TURN_RIGHT_TWICE ;
266
+ if (isExploring ) {
267
+ explorer .updateRobotOrientation (Movement .TURN_RIGHT );
268
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
269
+ }
236
270
}
237
271
break ;
238
272
case WEST :
239
273
if (nextOri == Orientation .NORTH ) {
240
274
_robot .turnRight ();
241
- return Movement .TURN_RIGHT ;
275
+ if (isExploring ) {
276
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
277
+ }
242
278
} else if (nextOri == Orientation .SOUTH ) {
243
279
_robot .turnLeft ();
244
- return Movement .TURN_LEFT ;
280
+ if (isExploring ) {
281
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
282
+ }
245
283
} else if (nextOri == Orientation .EAST ) {
246
284
_robot .turnRight ();
285
+ if (isExploring ) {
286
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
287
+ }
247
288
_robot .turnRight ();
248
- return Movement .TURN_RIGHT_TWICE ;
289
+ if (isExploring ) {
290
+ explorer .setIsExplored (explorer .getRobotPosition (), explorer .getRobotOrientation (), hasCalibration );
291
+ }
249
292
}
250
293
}
251
- return null ;
252
294
}
253
295
254
296
private Orientation getOrientationIfMoveToNeighbor (Orientation curOri , int curX , int curY , int nextX , int nextY ) {
0 commit comments