Recover around invalid navigation paths
This commit is contained in:
1 parent
5f5dde1a62
commit
c2b595a70d
4 files changed
+162
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.bot import _recover_invalid_path
|
||||
from mosfet.game import Game
|
||||
from mosfet.info import blocks
|
||||
from mosfet.path import Pathfinder
|
||||
@@ -42,6 +44,67 @@ class DoorNavigationTests(unittest.TestCase):
|
||||
finder = Pathfinder(g)
|
||||
self.assertFalse(finder.bair((1, 64, 0)))
|
||||
|
||||
def test_path_prefix_detects_new_obstacles_and_missing_support(self):
|
||||
class TerrainChunks:
|
||||
def __init__(self):
|
||||
self.states = {}
|
||||
|
||||
def get_block_at(self, x, y, z):
|
||||
position = (x, y, z)
|
||||
if position in self.states:
|
||||
return self.states[position]
|
||||
return blocks.STONE if y == 63 else blocks.AIR
|
||||
|
||||
chunks = TerrainChunks()
|
||||
g = Munch(chunks=chunks, crawling=False, unopenable_doors=set())
|
||||
route = [(1, 64, 0), (2, 64, 0), (3, 64, 0)]
|
||||
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(
|
||||
(0, 64, 0), route)
|
||||
self.assertTrue(valid)
|
||||
self.assertIsNone(invalid_node)
|
||||
|
||||
chunks.states[(2, 64, 0)] = blocks.STONE
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(
|
||||
(0, 64, 0), route)
|
||||
self.assertFalse(valid)
|
||||
self.assertEqual(invalid_node, (2, 64, 0))
|
||||
|
||||
chunks.states.clear()
|
||||
chunks.states[(2, 63, 0)] = blocks.AIR
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(
|
||||
(0, 64, 0), route)
|
||||
self.assertFalse(valid)
|
||||
self.assertEqual(invalid_node, (2, 64, 0))
|
||||
|
||||
def test_invalid_path_is_replanned_to_its_original_destination(self):
|
||||
class FakePathfinder:
|
||||
@staticmethod
|
||||
def path_prefix_is_valid(*_args, **_kwargs):
|
||||
return False, (1, 64, 0)
|
||||
|
||||
class FakeWorld:
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
|
||||
def path_to_place(self, start, goal):
|
||||
self.calls.append((start, goal))
|
||||
return [start, (1, 64, 0), goal]
|
||||
|
||||
world = FakeWorld()
|
||||
g = Munch(
|
||||
path=[(1, 64, 0), (2, 64, 0), (5, 64, 0)],
|
||||
pos=(0, 64, 0), on_ground=True, y_v=0,
|
||||
path_validation_at=0, navigation_recovery_target=None,
|
||||
navigation_retry_at=0, world=world)
|
||||
|
||||
with patch('mosfet.bot.path.Pathfinder', return_value=FakePathfinder()):
|
||||
_recover_invalid_path(g, now=1.0)
|
||||
|
||||
self.assertEqual(world.calls, [((0, 64, 0), (5, 64, 0))])
|
||||
self.assertEqual(g.path, [(0, 64, 0), (1, 64, 0), (5, 64, 0)])
|
||||
self.assertIsNone(g.navigation_recovery_target)
|
||||
|
||||
def test_pressure_plate_opened_door_is_not_toggled_or_closed(self):
|
||||
door = (1, 64, 0)
|
||||
after = (2, 64, 0)
|
||||
|
||||
Reference in new issue
Block a user