-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRammerBot.java
More file actions
73 lines (61 loc) · 1.68 KB
/
RammerBot.java
File metadata and controls
73 lines (61 loc) · 1.68 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
package Gamma;
import robocode.*;
//import java.awt.Color;
// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
/**
* RammerBot - a robot by (your name here)
*/
public class RammerBot extends Robot
{
/**
* run: RammerBot's default behavior
*/
public void run() {
// Initialization of the robot should be put here
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
setColors(Color.black,Color.red,Color.green); // body,gun,radar
// Robot main loop
while(true) {
// Replace the next 4 lines with any behavior you would like
ahead(100);
turnGunRight(360);
back(100);
turnGunRight(360);
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
// Replace the next line with any behavior you would like
if (e.getBearing() >= 0) {
turnDirection = 1;
} else {
turnDirection = -1;
}
turnRight(e.getBearing());
ahead(e.getDistance() + 5);
scan(); // Might want to move ahead again!
//Determine a shot that won't kill the robot...
//We want to ram him instead for bonus points!
if (e.getEnergy() > 16) {
fire(3);
} else if (e.getEnergy() > 10) {
fire(2);
} else if (e.getEnergy() > 4) {
fire(1);
} else if (e.getEnergy() > 2) {
fire(.5);
} else if (e.getEnergy() > .4) {
fire(.1);
}
ahead(40); // Ram him again!
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
// Replace the next line with any behavior you would like
}
}