Skip to content

Commit 84019c5

Browse files
Merge pull request #7 from robocode-dev/add-spinbot-bot
Add SpinBot bot (Java)
2 parents b77618e + 3e57f65 commit 84019c5

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

bots/java/SpinBot/SpinBot.cmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@echo off
2+
setlocal
3+
set BOT_API_VERSION=1.1.0
4+
if "%RUMBLE_JAVA_CACHE%"=="" set RUMBLE_JAVA_CACHE=%USERPROFILE%\.cache\rumble-bots-java
5+
if not exist "%RUMBLE_JAVA_CACHE%" mkdir "%RUMBLE_JAVA_CACHE%"
6+
set JAR=%RUMBLE_JAVA_CACHE%\robocode-tankroyale-bot-api-%BOT_API_VERSION%.jar
7+
if not exist "%JAR%" curl -fsSL -o "%JAR%" "https://repo1.maven.org/maven2/dev/robocode/tankroyale/robocode-tankroyale-bot-api/%BOT_API_VERSION%/robocode-tankroyale-bot-api-%BOT_API_VERSION%.jar"
8+
java -cp "%JAR%" "%~dp0src\SpinBot.java" %*

bots/java/SpinBot/SpinBot.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "SpinBot",
3+
"version": "1.0.0",
4+
"authors": ["Mathew Nelson", "Flemming N. Larsen"],
5+
"description": "Continuously moves in a circle while firing at maximum power at any bot it detects.",
6+
"platform": "JVM",
7+
"programmingLang": "Java 17",
8+
"gameTypes": ["1v1", "melee", "twinduel"],
9+
"license": "Apache-2.0"
10+
}

bots/java/SpinBot/SpinBot.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
4+
BOT_API_VERSION=1.1.0
5+
CACHE_DIR="${RUMBLE_JAVA_CACHE:-$HOME/.cache/rumble-bots-java}"
6+
JAR="$CACHE_DIR/robocode-tankroyale-bot-api-$BOT_API_VERSION.jar"
7+
if [ ! -f "$JAR" ]; then
8+
mkdir -p "$CACHE_DIR"
9+
curl -fsSL -o "$JAR.tmp" "https://repo1.maven.org/maven2/dev/robocode/tankroyale/robocode-tankroyale-bot-api/$BOT_API_VERSION/robocode-tankroyale-bot-api-$BOT_API_VERSION.jar"
10+
mv "$JAR.tmp" "$JAR"
11+
fi
12+
exec java -cp "$JAR" "$SCRIPT_DIR/src/SpinBot.java" "$@"

bots/java/SpinBot/src/SpinBot.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)