-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDMoD.java
More file actions
102 lines (86 loc) · 2.41 KB
/
Copy pathDMoD.java
File metadata and controls
102 lines (86 loc) · 2.41 KB
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
package aquila;
import robocode.*;
import java.awt.Color;
/**
* DetlefMaxwellOfDoom - a robot by Dominik
*/
public class DMoD extends AdvancedRobot {
int round;
byte scanDirection = 2;
public void run() {
setBodyColor(Color.green);
setGunColor(Color.black);
setRadarColor(Color.green);
setBulletColor(Color.yellow);
setScanColor(Color.red);
round = 0;
// Robot main loop
turnRadarLeft(360);
while (true) {
round++;
out.println("Round: " + round);
radarControl();
ahead(111);
execute();
}
}
public void onScannedRobot(ScannedRobotEvent e) {
double bearing = e.getBearing();
double distance = e.getDistance();
radarControl();
if (getEnergy() < 20) {
turnRight(bearing);
ahead(100);
}
if (distance < 450) {
fireControl(bearing, distance);
}
ahead(52);
}
public void radarControl() {
scanDirection *= -1;
setTurnRadarRight(360 * scanDirection);
}
public void fireControl(double bearing, double distance) {
double heading = getHeading();
double gunheading = getGunHeading();
double x = heading + bearing + gunheading * -1;
if (getGunHeat() == 0 && getEnergy() > 5) {
turnGunRight(x);
openFire(distance);
}
}
public void openFire(double distance) {
out.println("Enemy under fire!");
short max = 250;
byte min = 20;
if (distance > max) {
fire(1.5);
}
if ((distance >= min) && (distance <= max)) {
fire(2.5);
}
if (distance < min) {
fire(Rules.MAX_BULLET_POWER);
}
}
public void abstauber() {
}
public void onHitByBullet(HitByBulletEvent e) {
out.println("We are under fire!");
ahead(50);
}
public void onHitWall(HitWallEvent e) {
double bearing = e.getBearing();
if (bearing > 0) {
turnRight(bearing);
} else {
turnRight(45);
}
ahead(75);
}
public void onHitRobot(HitRobotEvent e) {
double bearing = e.getBearing();
fireControl(bearing, 15);
}
}