forked from abhishekdoifode1/Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot-Robocode.java
More file actions
99 lines (82 loc) · 2.29 KB
/
Robot-Robocode.java
File metadata and controls
99 lines (82 loc) · 2.29 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
package PP;
import robocode.*;
import robocode.util.Utils;
//import java.awt.Color;
// API help : https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html
public class Robozinho extends AdvancedRobot
{
/**
* run: Robozinho's default behavior
*/
public void atira(ScannedRobotEvent e) {
double forca = decideForca(e);
setFire(forca);
}
public double decideForca(ScannedRobotEvent e) {
double forca;
if(getOthers() == 1) {
forca = 2.0;
}
else {
forca = 3.0;
}
//se a distancia for grande reduz a forca
if (e.getDistance() > 400) {
forca = 1.0;
}
// cc aumenta a forca
else if (e.getDistance() < 200) {
forca = 3.0;
}
//se a energia tiver baixa reduz a forca
if (getEnergy() < 10) {
forca = 1.0;
}
else if (getEnergy() < 1) {
forca = 0.1;
}
return Math.min(e.getEnergy()/4, forca);
}
public void run() {
int cont = 0;
// gun e radar independentes
setAdjustRadarForGunTurn(true);
setAdjustRadarForRobotTurn(true);
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
// setColors(Color.red,Color.blue,Color.green); // body,gun,radar
// Robot main loop
while(true) {
// radar rotaciona infinitamente quando nao ha movimento agendado
if(getRadarTurnRemaining() == 0.0) {
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
}
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
double angleToEnemy = getHeadingRadians() + e.getBearingRadians();
double turnToEnemy = Utils.normalRelativeAngle(angleToEnemy - getRadarHeadingRadians());
double extraTurn = Math.atan(36.0/ e.getDistance())*(turnToEnemy >= 0 ? 1 : -1);
setTurnRadarRightRadians (turnToEnemy + extraTurn);
// fica perpendicular ao inimigo
setTurnRadarRightRadians(turnToEnemy + extraTurn); //radar vira
setTurnRight(e.getBearing() + 90); // corpo do robo vira
}
/**
* 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
back(10);
}
/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
// Replace the next line with any behavior you would like
back(20);
}
}