-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrendanSwords21335265.java
More file actions
113 lines (85 loc) · 2.04 KB
/
BrendanSwords21335265.java
File metadata and controls
113 lines (85 loc) · 2.04 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
package bs;
import robocode.*;
import java.lang.Math.*;
import java.awt.Color;
public class BrendanSwords21335265 extends AdvancedRobot
{
int forwardOrBack = 1;
boolean forwardVelocity = false;
Color bodyColor = new Color(0.38f, 1.0f, 0.31f);
Color gunColor = new Color(0.97f,0.48f,1f);
Color radarColor = new Color(0f, 1f, 0.945f);
int noOfRobots = 0;
public void run(){
setColors(bodyColor, gunColor, radarColor);
noOfRobots = getOthers();
boolean start = true;
while(start){
if(noOfRobots>16){
setMaxVelocity(5);
setTurnRight(10000);
setAhead(10000);
execute();
}else{
setAdjustRadarForRobotTurn(true);
turnRadarRight(360000);
}
}
}
public void onScannedRobot(ScannedRobotEvent e) {
if(noOfRobots > 16){
setFire(3);
execute();
return;
}
if(e.isSentryRobot()){
double centerAngle = Math .atan2(getBattleFieldWidth()/2-getX(), getBattleFieldHeight()/2-getY());
setTurnRightRadians(fixAim(centerAngle - getHeadingRadians()));
setAhead(100);
return;
}
if((Math.random() * 1000) > 998){
setTurnRight(90);
}
setTurnRadarLeft(getRadarTurnRemaining());
if(e.getDistance() >= 150){
double turnDistance = fixAim( e.getBearing() + getHeading() - getGunHeading() );
if(e.getVelocity() < 5){
setTurnGunRight(turnDistance);
}else{
setTurnGunRight(turnDistance + 20);
}
setAhead((e.getDistance() - 100) * forwardOrBack);
setFire(2);
System.out.println("2!");
}else{
double turnDistance = fixAim( e.getBearing() + getHeading() - getGunHeading() );
setTurnGunRight(turnDistance);
setFire(3);
System.out.println("3!");
}
}
public void onHitRobotEvent(HitRobotEvent e){
if(e.isMyFault()){
setBack(50);
}
}
public double fixAim(double angle){
if(angle > 180){return angle-360;}
if(angle < -180){return angle+360;}
return angle;
}
public void onHitWall(HitWallEvent e) {
if(noOfRobots > 16){
if(forwardVelocity){
setBack(1000);
forwardVelocity = false;
}else{
setAhead(1000);
forwardVelocity = true;
}
}else{
forwardOrBack *= -1;
}
}
}