Validate routes across crawl-mode changes
This commit is contained in:
1 parent
777018d24b
commit
928ce064eb
2 files changed
+31
-5
No files matched your search
+23
-5
@@ -276,13 +276,30 @@ class Pathfinder(AStar):
|
|||||||
node = tuple(node)
|
node = tuple(node)
|
||||||
if not self.bair(node) or self.bavoid(node):
|
if not self.bair(node) or self.bavoid(node):
|
||||||
return False
|
return False
|
||||||
if not self.g.get('crawling'):
|
|
||||||
above = utils.padd(node, BLOCK_ABOVE)
|
|
||||||
if not self.bair(above) or self.bavoid(above):
|
|
||||||
return False
|
|
||||||
below = utils.padd(node, BLOCK_BELOW)
|
below = utils.padd(node, BLOCK_BELOW)
|
||||||
return not self.bair(below) and not self.bavoid(below)
|
return not self.bair(below) and not self.bavoid(below)
|
||||||
|
|
||||||
|
def _path_edge_is_valid(self, start, end):
|
||||||
|
offset = utils.psub(end, start)
|
||||||
|
if offset in TRAVERSE:
|
||||||
|
# A changed ceiling can put the bot into crawl mode without
|
||||||
|
# invalidating an otherwise traversable horizontal step.
|
||||||
|
return (self.check_traverse(start, offset) or
|
||||||
|
self.check_traverse_crawling(start, offset))
|
||||||
|
if offset in DIAGONAL:
|
||||||
|
return self.check_diagonal(start, offset)
|
||||||
|
if offset in ASCEND:
|
||||||
|
return self.check_ascend(start, offset)
|
||||||
|
if offset in DESCEND:
|
||||||
|
return self.check_descend(start, offset)
|
||||||
|
if offset in DESCEND2:
|
||||||
|
return self.check_descend2(start, offset)
|
||||||
|
if offset in DESCEND3:
|
||||||
|
return self.check_descend3(start, offset)
|
||||||
|
if offset in PARKOUR:
|
||||||
|
return self.check_parkour(start, offset)
|
||||||
|
return False
|
||||||
|
|
||||||
def path_prefix_is_valid(self, route, steps=2):
|
def path_prefix_is_valid(self, route, steps=2):
|
||||||
"""Check upcoming route nodes against the current loaded block state."""
|
"""Check upcoming route nodes against the current loaded block state."""
|
||||||
previous = None
|
previous = None
|
||||||
@@ -290,7 +307,8 @@ class Pathfinder(AStar):
|
|||||||
node = tuple(point)
|
node = tuple(point)
|
||||||
if not self._can_stand_at(node):
|
if not self._can_stand_at(node):
|
||||||
return False, node
|
return False, node
|
||||||
if previous is not None and node not in self.neighbors(previous):
|
if (previous is not None and
|
||||||
|
not self._path_edge_is_valid(previous, node)):
|
||||||
return False, node
|
return False, node
|
||||||
previous = node
|
previous = node
|
||||||
return True, None
|
return True, None
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ class DoorNavigationTests(unittest.TestCase):
|
|||||||
self.assertTrue(valid)
|
self.assertTrue(valid)
|
||||||
self.assertIsNone(invalid_node)
|
self.assertIsNone(invalid_node)
|
||||||
|
|
||||||
|
# A low ceiling can switch traversal to crawling without making the
|
||||||
|
# horizontal path edge invalid.
|
||||||
|
chunks.states[(1, 65, 0)] = blocks.STONE
|
||||||
|
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
|
||||||
|
self.assertTrue(valid)
|
||||||
|
self.assertIsNone(invalid_node)
|
||||||
|
|
||||||
|
chunks.states.clear()
|
||||||
chunks.states[(2, 64, 0)] = blocks.STONE
|
chunks.states[(2, 64, 0)] = blocks.STONE
|
||||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
|
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
|
||||||
self.assertFalse(valid)
|
self.assertFalse(valid)
|
||||||
|
|||||||
Reference in new issue
Block a user