-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDumboController.java
More file actions
36 lines (27 loc) · 822 Bytes
/
DumboController.java
File metadata and controls
36 lines (27 loc) · 822 Bytes
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
/*
* File: DumboController.java
* Created: 17 September 2002, 00:34
* Author: Stephen Jarvis
*/
import uk.ac.warwick.dcs.maze.logic.IRobot;
public class DumboController
{
public void controlRobot(IRobot robot) {
int randno;
int direction;
// Select a random number
while(true){
randno = (int) Math.round(Math.random()*3);
// Convert this to a direction
if (randno == 0)
direction = IRobot.LEFT;
else if (randno == 1)
direction = IRobot.RIGHT;
else if (randno == 2)
direction = IRobot.BEHIND;
else
direction = IRobot.AHEAD;
if(robot.look(IRobot.Ahead) == I.Robot.WALL){
robot.face(direction); /* Face the robot in this direction */
}
}