-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMegaBorsten2000.java
More file actions
175 lines (147 loc) · 4.97 KB
/
Copy pathMegaBorsten2000.java
File metadata and controls
175 lines (147 loc) · 4.97 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package aquila;
import robocode.*;
import java.awt.Color;
/**
* Borsten - a robot by Dome
* Ideen: Bullets verfolgen; eigene und feindliche
* Zirkeln
*/
public class MegaBorsten2000 extends AdvancedRobot {
//für Radar- und Fahrtrichtungswechsel
byte dirRadar = 1;
byte dirDrive = 1;
int i;
public void run() {
setAdjustRadarForGunTurn(true);
setGunColor(Color.orange);
setScanColor(Color.lightGray);
setRadarColor(Color.darkGray);
setBodyColor(Color.gray);
setBulletColor(Color.white);
while (true) {
i++;
System.out.println("\nRunde: " + i);
if (getGunHeat() <= 0)
System.out.println("Ready to fire!");
stayAway();
setTurnRadarLeft(55 * dirRadar);
setAhead(40 * dirDrive);
execute();
}
}
public void onScannedRobot(ScannedRobotEvent e) {
dirRadar *= -1;
setTurnRadarRight(getHeading() - getRadarHeading() + e.getBearing());
//get bearing of scanned robot -180 to 180
double bearing = e.getBearing();
double distance = e.getDistance();
//get heading of scanned robot 0 -360
//System.out.println("H: "+heading+" EH: "+getHeading() + " y: "+y);
//get energy of scanned robot
//double energy = e.getEnergy();
String name = e.getName();
//double velocity = e.getVelocity();
if (distance < 440) {
fireControl(bearing, distance, name);
}
if (distance < 370) {
setTurnRight(bearing + 90);
} else {
setTurnRight(bearing + 20);
}
}
public void stayAway() {
double h = getBattleFieldHeight();
double w = getBattleFieldWidth();
double x = getX();
double y = getY();
//System.out.println("X: "+getX()+" Y: "+getY()+" H: "+getHeading());
if (y < h / 10) {
System.out.println("//zu weit unten");
//setMaxVelocity(0);
} else if (y > h - h / 10) {
System.out.println("//zu weit oben");
} else if (x < w / 10) {
System.out.println("//zu weit links");
} else if (x > h - h / 10) {
System.out.println("//zu weit rechts");
}
}
public void fireControl(double bearing, double distance, String name) {
double heading = getHeading();
//Returns direction the gun is facing, in degrees. The value will be between 0 and 360
double gunheading = getGunHeading();
double x = heading + bearing + (gunheading * -1);
if (x >= 181) {
//System.out.println("Korrigiere von X = "+x);
x = x - 360;
} else if (x <= -181) {
//System.out.println("Korrigiere von X = "+x);
x = x + 360;
}
if (getGunHeat() <= 0 && getEnergy() > 5) {
//System.out.println("Distance to the enemy: "+distance + " X: "+x);
turnGunRight(x);
openFire(distance, name);
}
}
public void openFire(double distance, String name) {
System.out.println("Open the fire on " + name + "!");
short max = 290;
byte min = 50;
if (distance <= min) {
fire(Rules.MAX_BULLET_POWER);
}
if ((distance > min) && (distance <= max)) {
fire(Rules.MAX_BULLET_POWER / 2);
}
fire(Rules.MAX_BULLET_POWER / 3);
}
public void onHitByBullet(HitByBulletEvent e) {
double bearing = e.getBearing();
Bullet bulltet = e.getBullet();
double heading = e.getHeading();
fuckYou(e.getName());
}
public void onHitRobot(HitRobotEvent e) {
double energy = e.getEnergy();
boolean myfault = e.isMyFault();
if (myfault == true && energy > getEnergy()) {
setAhead(102);
} else {
setBack(99);
}
fireControl(e.getBearing(), 22.2, e.getName());
fuckYou(e.getName());
}
public void onHitWall(HitWallEvent e) {
dirDrive *= -1;
}
public void onBulletMissed(BulletMissedEvent e) {
System.out.println("Damn!");
}
public void onRobotDeath(RobotDeathEvent e) {
// other robot dies...
fuckYou(e.getName());
}
public void onWinEvent() {
//party hard!
}
public void onRoundEnded(RoundEndedEvent event) {
System.out.println("Round " + i + " was the last!");
}
public void fuckYou(String name) {
String[] fuckyou = {"Fuck you ",
"I hate you ",
"You´re a piece of shit, ",
"You are worthless trash ",
"Candy Ass ",
"Hit the road, ",
"Eat my shorts, ",
"You've got the brains of a doughnut, ",
"You´re a randy old bugger, "
};
int rand = (int) (Math.random() * fuckyou.length);
System.out.println(fuckyou[rand] + name + "!");
}
}