lgbot: movement recorder (lgbot_record) and tools/lgbot_rec.py to compare player vs bot movement

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
esefandClaude Opus 5.5 committed 2026-10-15 18:32:22 +03:00
1 parent e1c64bed4c
commit 3535940331
6 files changed
+324 -5

No files matched your search

+30
View File
@@ -58,6 +58,9 @@ def load(world):
def get_cvar(self, name):
return world.cvars.get(name)
def set_cvar(self, name, value):
world.cvars[name] = value
def add_hook(self, event, fn):
pass
@@ -139,6 +142,33 @@ class Tick(unittest.TestCase):
# per frame: at most the acceleration step (plus friction compensation), never a 640 u/s flip
self.assertLess(biggest, self.mod.ACCEL * 0.025 * comp + 0.15 * 320 * comp + 1)
def test_recorder_writes_rows_without_names(self):
import tempfile
path = os.path.join(tempfile.mkdtemp(), "rec.csv")
self.mod.REC_FILE = path
self.w.cvars["lgbot_record"] = "1"
self.run_frames(80)
self.w.cvars["lgbot_record"] = "0"
self.w.now += 1.1 # cvars are reread once a second
self.run_frames(2)
with open(path) as f:
text = f.read()
rows = [l.split(",") for l in text.splitlines() if not l.startswith("#")]
self.assertGreater(len(rows), 100)
self.assertEqual({row[1] for row in rows}, {"bot", "h1"})
self.assertIn("steer", {row[10] for row in rows})
self.assertNotIn(str(HUMAN_ID), text)
self.assertIsNone(self.plugin.rec)
def test_recorder_stops_itself(self):
import tempfile
self.mod.REC_FILE = os.path.join(tempfile.mkdtemp(), "rec.csv")
self.mod.REC_MAX_S = 1
self.w.cvars["lgbot_record"] = "1"
self.run_frames(80)
self.assertEqual(self.w.cvars["lgbot_record"], "0")
self.assertIsNone(self.plugin.rec)
def test_no_target_means_no_steering(self):
self.human.team = "spectator"
self.run_frames(40)