|
| 1 | +import dev.robocode.tankroyale.botapi.*; |
| 2 | +import dev.robocode.tankroyale.botapi.events.*; |
| 3 | +import dev.robocode.tankroyale.botapi.graphics.Color; |
| 4 | + |
| 5 | +// ------------------------------------------------------------------ |
| 6 | +// SpinBot |
| 7 | +// ------------------------------------------------------------------ |
| 8 | +// A sample bot originally made for Robocode by Mathew Nelson. |
| 9 | +// |
| 10 | +// Continuously moves in a circle while firing at maximum power when |
| 11 | +// detecting enemies. |
| 12 | +// ------------------------------------------------------------------ |
| 13 | +public class SpinBot extends Bot { |
| 14 | + |
| 15 | + // The main method starts our bot |
| 16 | + public static void main(String[] args) { |
| 17 | + if ("1".equals(System.getenv("RUMBLE_SMOKE"))) { |
| 18 | + System.out.println("RUMBLE_SMOKE_READY SpinBot"); |
| 19 | + return; |
| 20 | + } |
| 21 | + new SpinBot().start(); |
| 22 | + } |
| 23 | + |
| 24 | + // Called when a new round is started -> initialize and do some movement |
| 25 | + @Override |
| 26 | + public void run() { |
| 27 | + setBodyColor(Color.BLUE); |
| 28 | + setTurretColor(Color.BLUE); |
| 29 | + setRadarColor(Color.BLACK); |
| 30 | + setScanColor(Color.YELLOW); |
| 31 | + |
| 32 | + // Repeat while the bot is running |
| 33 | + while (isRunning()) { |
| 34 | + // Tell the game that when we take move, we'll also want to turn right... a lot |
| 35 | + setTurnRight(10_000); |
| 36 | + // Limit our speed to 5 |
| 37 | + setMaxSpeed(5); |
| 38 | + // Start moving (and turning) |
| 39 | + forward(10_000); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + // We scanned another bot -> fire hard! |
| 44 | + @Override |
| 45 | + public void onScannedBot(ScannedBotEvent e) { |
| 46 | + fire(3); |
| 47 | + } |
| 48 | + |
| 49 | + // We hit another bot -> if it's our fault, we'll stop turning and moving, |
| 50 | + // so we need to turn again to keep spinning. |
| 51 | + @Override |
| 52 | + public void onHitBot(HitBotEvent e) { |
| 53 | + var direction = directionTo(e.getX(), e.getY()); |
| 54 | + var bearing = calcBearing(direction); |
| 55 | + if (bearing > -10 && bearing < 10) { |
| 56 | + fire(3); |
| 57 | + } |
| 58 | + if (e.isRammed()) { |
| 59 | + turnRight(10); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments