-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessFactorBot.java
More file actions
56 lines (49 loc) · 1.55 KB
/
GuessFactorBot.java
File metadata and controls
56 lines (49 loc) · 1.55 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
package Gamma;
import robocode.*;
//import java.awt.Color;
import java.awt.geom.*;
import robocode.util.Utils;
public class GuessFactorBot
{
//setColors(Color.black,Color.blue,Color.red);
private double startX, startY, startBearing, power;
private long fireTime;
private int direction;
private int[] returnSegment;
public GuessFactorBot(double x, double y, double bearing, double power,
int direction, long time, int[] segment)
{
startX = x;
startY = y;
startBearing = bearing;
this.power = power;
this.direction = direction;
fireTime = time;
returnSegment = segment;
}
public double getBulletSpeed()
{
return 20 - power * 3;
}
public double maxEscapeAngle()
{
return Math.asin(8 / getBulletSpeed());
}
public boolean checkHit(double enemyX, double enemyY, long currentTime)
{
// if the distance from the wave origin to our enemy has passed
// the distance the bullet would have traveled...
if (Point2D.distance(startX, startY, enemyX, enemyY) <=
(currentTime - fireTime) * getBulletSpeed())
{
double desiredDirection = Math.atan2(enemyX - startX, enemyY - startY);
double angleOffset = Utils.normalRelativeAngle(desiredDirection - startBearing);
double guessFactor =
Math.max(-1, Math.min(1, angleOffset / maxEscapeAngle())) * direction;
int index = (int) Math.round((returnSegment.length - 1) /2 * (guessFactor + 1));
returnSegment[index]++;
return true;
}
return false;
}
} // end GuessFactorBot class