Skip to content

Commit 564aabb

Browse files
Merge pull request #4 from robocode-dev/ch-032-add-vector
Add Vector for the live Rumble proof
2 parents 7f010e3 + bf8543c commit 564aabb

5 files changed

Lines changed: 61 additions & 3 deletions

File tree

bots/python/Vector/Vector.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
python "%~dp0src\Vector.py" %*

bots/python/Vector/Vector.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "Vector",
3+
"version": "1.0.0",
4+
"authors": ["Tank Royale Rumble maintainers"],
5+
"description": "A small source-only bot that drives in wide arcs across the arena.",
6+
"platform": "Python",
7+
"programmingLang": "Python 3",
8+
"gameTypes": ["1v1", "melee", "twinduel"],
9+
"license": "Apache-2.0"
10+
}

bots/python/Vector/Vector.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
4+
if [ -n "${RUMBLE_PYTHON:-}" ]; then
5+
exec "$RUMBLE_PYTHON" "$SCRIPT_DIR/src/Vector.py" "$@"
6+
fi
7+
if command -v python3 >/dev/null 2>&1; then
8+
exec python3 "$SCRIPT_DIR/src/Vector.py" "$@"
9+
fi
10+
exec python "$SCRIPT_DIR/src/Vector.py" "$@"

bots/python/Vector/src/Vector.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""A compact Rumble catalog bot used for the first live ranked 1v1 proof."""
2+
3+
import os
4+
5+
6+
if os.environ.get("RUMBLE_SMOKE") == "1":
7+
print("RUMBLE_SMOKE_READY Vector")
8+
raise SystemExit(0)
9+
10+
from robocode_tank_royale.bot_api.bot import Bot
11+
from robocode_tank_royale.bot_api.events import ScannedBotEvent
12+
13+
14+
class Vector(Bot):
15+
"""Sweeps the radar while travelling in a wide arc."""
16+
17+
def run(self) -> None:
18+
self.turn_radar_right(360)
19+
while self.running:
20+
self.set_turn_right(30)
21+
self.forward(10_000)
22+
23+
def on_scanned_bot(self, event: ScannedBotEvent) -> None:
24+
"""Aim at the detected opponent and fire before continuing the scan."""
25+
self.turn_gun_right(self.gun_bearing_to(float(event.x), float(event.y)))
26+
self.fire(3)
27+
self.rescan()
28+
29+
30+
def main() -> None:
31+
Vector().start()
32+
33+
34+
if __name__ == "__main__":
35+
main()

tests/test_validate_bot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def test_valid_submission_generates_an_active_catalog_entry(self) -> None:
7373
result = self.run_validator("--smoke", "--generate")
7474
self.assertEqual(0, result.returncode, result.stderr)
7575
catalog = json.loads((self.root / "bots" / "index.json").read_text(encoding="utf-8"))
76-
active_entry = next(entry for entry in catalog["bots"] if entry["status"] == "active")
77-
self.assertEqual("Orbit", active_entry["name"])
76+
orbit = next(entry for entry in catalog["bots"] if entry["name"] == "Orbit")
77+
self.assertEqual("active", orbit["status"])
7878

7979
def test_invalid_license_is_rejected(self) -> None:
8080
config_path = self.root / "bots" / "python" / "Orbit" / "Orbit.json"
@@ -101,7 +101,8 @@ def test_version_increase_supersedes_the_previous_catalog_entry(self) -> None:
101101
config_path.write_text(json.dumps(config), encoding="utf-8")
102102
self.assertEqual(0, self.run_validator("--generate").returncode)
103103
catalog = json.loads((self.root / "bots" / "index.json").read_text(encoding="utf-8"))
104-
self.assertEqual(["superseded", "active"], [entry["status"] for entry in catalog["bots"]])
104+
orbit = [entry for entry in catalog["bots"] if entry["name"] == "Orbit"]
105+
self.assertEqual(["superseded", "active"], [entry["status"] for entry in orbit])
105106

106107
def test_new_bot_from_another_owner_ignores_unchanged_catalog_entries(self) -> None:
107108
self.assertEqual(0, self.run_validator("--generate").returncode)

0 commit comments

Comments
 (0)