-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobrrRat.java
More file actions
55 lines (46 loc) · 1.54 KB
/
RobrrRat.java
File metadata and controls
55 lines (46 loc) · 1.54 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
package SacdalanYoung_src;
import java.util.*;
import robocode.*;
import robocode.util.*;
import java.awt.Color;
// API help : https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html
//RobrrRat - a robot by Lance Sacdalan and Sophia Young
public class RobrrRat extends AdvancedRobot {
// Random value for unpredictive movement
private Random random = new Random();
public void run() {
setColors(Color.black,Color.white,Color.red); // body,gun,radar
// Robot main loop
while(true) {
// Continuous scanning in all directions
turnGunRight(360);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
// Variables needed
double distance = e.getDistance();
// For unpredictive movement
setAhead(random.nextDouble() * 360.0);
setTurnRight(random.nextDouble() * 360.0);
// Aims to increase bullet damage input and survivability in different range of combat
if (distance < 270) {
// To acquire the enemy position
double direction = getHeadingRadians() + e.getBearingRadians();
// Formula for targeting (normalize bearing)
setTurnGunRightRadians(Utils.normalRelativeAngle(direction - getGunHeadingRadians()));
setFire(3);
}
else { // Momentary switch of input
// Go near target
setTurnRight(e.getBearing());
// Maintain agility of robot
setFire(Math.min(3, getEnergy() / 2));
}
// Execute other actions
execute();
}
public void onHitWall(HitWallEvent e) {
// Go near target
setTurnRight(e.getBearing() + 90);
}
}