-
Notifications
You must be signed in to change notification settings - Fork 21
/
CustomTeamA.java
77 lines (57 loc) · 1.48 KB
/
CustomTeamA.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
public class CustomTeamA implements Team{
public String getTeamName(){
return "Emerotecos";
}
public void setTeamSide(TeamSide side){
}
public Robot buildRobot(GameSimulator s, int index){
if(index == 0)
return new Attacker(s);
if(index == 1)
return new Goalier(s);
// By default, return a new attacker
return new Attacker(s);
}
class Attacker extends RobotBasic{
Attacker(GameSimulator s){
super(s);
}
float speedMultiplier = (float)Math.random() * 5 + 5;
Sensor locator;
public void setup(){
System.out.println("Running!");
locator = getSensor("BALL");
}
public void loop(){
float angle = locator.readValue(0);
setRotation(angle * speedMultiplier);
setSpeed(0.5f,0);
delay(100);
}
}
class Goalier extends RobotBasic{
Goalier(GameSimulator s){
super(s);
}
float divisor = (float)Math.random() * 150 + 70;
Sensor locator;
// Front, left, back, right
Sensor[] ultrasonic_sensors = new Sensor[4];
public void run(){
locator = getSensor("BALL");
ultrasonic_sensors[0] = getSensor("ULTRASONIC_FRONT");
ultrasonic_sensors[1] = getSensor("ULTRASONIC_LEFT");
ultrasonic_sensors[2] = getSensor("ULTRASONIC_BACK");
ultrasonic_sensors[3] = getSensor("ULTRASONIC_RIGHT");
System.out.println("Running!");
while(true){
float angle = locator.readValue(0);
if(Math.abs(angle) < 90)
setSpeed(0f, angle / divisor);
else
setSpeed(0f, 0f);
delay(100);
}
}
}
}