lgbot: steer only within LG reach on the same floor; let the AI walk around walls

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
esefandClaude Opus 5.5 committed 2026-10-15 14:59:56 +03:00
1 parent f494223305
commit a998614224
4 files changed
+89 -22

No files matched your search

+29 -5
View File
@@ -1,7 +1,7 @@
import math, os, random, sys, unittest
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "home", "minqlx-plugins"))
from lgbot import (PRESETS, KEYS, resolve, Strafer, wanted_range, steer, fix_z, pick_target, to_int, is_bot, is_lgbot)
from lgbot import (PRESETS, KEYS, resolve, Strafer, wanted_range, steer, fix_z, pick_target, to_int, is_bot, is_lgbot, StuckGuard)
def preset(n, **kw):
@@ -156,10 +156,34 @@ class Misc(unittest.TestCase):
self.assertIsNone(to_int(None))
def test_pick_target(self):
c = [((300, 0), "near"), ((900, 0), "far")]
self.assertEqual(pick_target((0, 0), c), "near")
self.assertIsNone(pick_target((0, 0), [((2000, 0), "x")]))
self.assertIsNone(pick_target((0, 0), []))
c = [((300, 0, 0), "near"), ((800, 0, 0), "far")]
self.assertEqual(pick_target((0, 0, 0), c), "near")
self.assertIsNone(pick_target((0, 0, 0), [((1000, 0, 0), "x")])) # beyond LG reach: AI walks there
self.assertIsNone(pick_target((0, 0, 0), []))
def test_pick_target_ignores_other_floors(self):
c = [((200, 0, 300), "above"), ((600, 0, 40), "same floor")]
self.assertEqual(pick_target((0, 0, 0), c), "same floor")
self.assertIsNone(pick_target((0, 0, 0), [((200, 0, -300), "below")]))
class Stuck(unittest.TestCase):
def test_steers_while_moving(self):
g = StuckGuard()
self.assertTrue(all(g.update(t, 320, 300) for t in range(0, 3000, 25)))
def test_lets_go_when_blocked_then_retries(self):
g = StuckGuard()
results = [(t, g.update(t, 320, 50)) for t in range(0, 4000, 25)]
first_off = next(t for t, ok in results if not ok)
self.assertTrue(450 <= first_off <= 550)
back_on = next(t for t, ok in results if t > first_off and ok)
self.assertTrue(1900 <= back_on - first_off + 500 <= 2100) # off for 1.5 s
def test_short_bump_is_fine(self):
g = StuckGuard()
ok = [g.update(t, 320, 50 if 1000 <= t < 1300 else 300) for t in range(0, 3000, 25)]
self.assertTrue(all(ok))
import json, tempfile