1 import interfaces.Controller;
2 import interfaces.AbstractRobot;
3
4 import java.lang.*;
5 import java.util.*;
6
7
12 public class HandCodedLightSeeker extends Controller
13 {
14 private AbstractRobot robot;
15 private boolean running;
16
17 private int[] sensors={Controller.SENSOR_TYPE_LIGHT,Controller.SENSOR_TYPE_LIGHT,Controller.SENSOR_TYPE_LIGHT};
18
19
22
23 public void initController(AbstractRobot r)
24 {
25 robot=r;
26 }
27
28 public int[] getSensors()
29 {
30 return sensors;
31 }
32
33 public void halt()
34 {
35 running=false;
38
39 robot.stopMoving();
41 }
42
43 public AbstractRobot getRobot()
44 {
45 return robot;
46 }
47
48 public void run()
49 {
50 running=true;
52
53 while (running)
55 {
56
59 if(robot.getSensor1() > robot.getSensor2() && robot.getSensor2() > robot.getSensor3()){robot.left();}
60 if(robot.getSensor1() > robot.getSensor2() && robot.getSensor2() < robot.getSensor3()){robot.left();}
61 if(robot.getSensor1() < robot.getSensor2() && robot.getSensor2() > robot.getSensor3()){robot.forward();}
62 if(robot.getSensor1() < robot.getSensor2() && robot.getSensor2() < robot.getSensor3()){robot.right();}
63
64 try{sleep(500);}catch(Exception e){}
65 }
66 }
67 }
68