-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVelociRobot.java
59 lines (49 loc) · 1.34 KB
/
VelociRobot.java
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
/**
* Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
package sample;
import robocode.HitByBulletEvent;
import robocode.HitWallEvent;
import robocode.RateControlRobot;
import robocode.ScannedRobotEvent;
/**
* This is a sample of a robot using the RateControlRobot class
*
* @author Joshua Galecki (original)
*/
public class VelociRobot extends RateControlRobot {
int turnCounter;
public void run() {
turnCounter = 0;
setGunRotationRate(15);
while (true) {
if (turnCounter % 64 == 0) {
// Straighten out, if we were hit by a bullet and are turning
setTurnRate(0);
// Go forward with a velocity of 4
setVelocityRate(4);
}
if (turnCounter % 64 == 32) {
// Go backwards, faster
setVelocityRate(-6);
}
turnCounter++;
execute();
}
}
public void onScannedRobot(ScannedRobotEvent e) {
fire(1);
}
public void onHitByBullet(HitByBulletEvent e) {
// Turn to confuse the other robot
setTurnRate(5);
}
public void onHitWall(HitWallEvent e) {
// Move away from the wall
setVelocityRate(-1 * getVelocityRate());
}
}