Align bed placement along supported lanes
This commit is contained in:
1 parent
243e34e26f
commit
1b4f32060d
5 files changed
+208
-75
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import unittest
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.bot import update_yaw
|
||||
from mosfet.info import blocks
|
||||
from mosfet.jobs.sleep_with_bed import SleepWithBedStates
|
||||
from mosfet.vector import Vector3D
|
||||
from mosfet.world import BedArea, World
|
||||
|
||||
|
||||
class BedLaneTests(unittest.TestCase):
|
||||
def make_world(self, supported):
|
||||
class GridChunks:
|
||||
def get_block_at(self, x, y, z):
|
||||
if y == 63 and (x, y, z) in supported:
|
||||
return blocks.STONE
|
||||
return blocks.AIR
|
||||
|
||||
return World(Munch(chunks=GridChunks(), mobs={}))
|
||||
|
||||
def test_bed_areas_require_standing_and_two_bed_tiles(self):
|
||||
supported = {(x, 63, 0) for x in (1, 2, 3)}
|
||||
world = self.make_world(supported)
|
||||
|
||||
layouts = list(world.find_bed_areas(
|
||||
(0, 64, 0), 4, include_layout=True))
|
||||
|
||||
self.assertIn(BedArea(
|
||||
foot=(2, 64, 0), head=(3, 64, 0),
|
||||
opening=(1, 64, 0), facing=(1, 0, 0)), layouts)
|
||||
self.assertIn((1, 64, 0), list(world.find_bed_areas((0, 64, 0), 4)))
|
||||
|
||||
def test_bed_lane_is_rejected_without_third_supported_block(self):
|
||||
supported = {(1, 63, 0), (2, 63, 0)}
|
||||
world = self.make_world(supported)
|
||||
|
||||
layouts = list(world.find_bed_areas(
|
||||
(0, 64, 0), 4, include_layout=True))
|
||||
|
||||
self.assertFalse(any(
|
||||
layout.opening == (1, 64, 0) for layout in layouts))
|
||||
|
||||
def test_far_end_aim_avoids_movement_yaw_dead_zone(self):
|
||||
yaw = Munch(yaw=0.0)
|
||||
update_yaw(yaw, Vector3D((-0.5, 0, 0)))
|
||||
self.assertEqual(yaw.yaw, 0.0)
|
||||
|
||||
for _ in range(4):
|
||||
update_yaw(yaw, Vector3D((-1.5, 0, 0)))
|
||||
self.assertAlmostEqual(yaw.yaw, -90.0)
|
||||
|
||||
def test_sleep_job_navigates_to_lane_end_and_aligns_before_placing(self):
|
||||
layout = BedArea(
|
||||
foot=(2, 64, 0), head=(3, 64, 0),
|
||||
opening=(1, 64, 0), facing=(1, 0, 0))
|
||||
|
||||
class PlacementWorld:
|
||||
def find_bed_areas(self, center, distance, include_layout=False):
|
||||
self.search = (center, distance, include_layout)
|
||||
return [layout]
|
||||
|
||||
def path_to_place(self, start, destination):
|
||||
self.path_call = (start, destination)
|
||||
return [destination]
|
||||
|
||||
class FakeGame:
|
||||
def __init__(self):
|
||||
self.placements = []
|
||||
|
||||
def place_block(self, location, face, hand=0, cursor_y=None):
|
||||
self.placements.append((location, face, hand, cursor_y))
|
||||
|
||||
world = PlacementWorld()
|
||||
game = FakeGame()
|
||||
state = SleepWithBedStates(Munch(
|
||||
pos=(0, 64, 0), yaw=0.0, path=[], look_at=None,
|
||||
world=world, game=game, holding_hand=0))
|
||||
state.state = state.find_bed_spot
|
||||
|
||||
state.find_bed_spot()
|
||||
self.assertEqual(world.path_call, ((0, 64, 0), layout.opening))
|
||||
self.assertEqual(state.area, layout.foot)
|
||||
self.assertEqual(state.g.path, [layout.opening])
|
||||
|
||||
state.g.pos = layout.opening
|
||||
state.going_to_area()
|
||||
self.assertEqual(state.g.look_at, layout.head)
|
||||
self.assertEqual(state.g.yaw_target_override, -90.0)
|
||||
self.assertEqual(state.state, state.turn_to_bed_area)
|
||||
|
||||
state.turn_to_bed_area()
|
||||
self.assertEqual(state.state, state.turn_to_bed_area)
|
||||
for _ in range(3):
|
||||
update_yaw(
|
||||
state.g, Vector3D((-1.5, 0, 0)),
|
||||
fixed_target=state.g.yaw_target_override)
|
||||
state.turn_to_bed_area()
|
||||
self.assertEqual(state.state, state.place_bed)
|
||||
|
||||
state.place_bed()
|
||||
self.assertEqual(game.placements[0][0], (2, 63, 0))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -76,7 +76,7 @@ class GatherWoodPortTests(unittest.TestCase):
|
||||
[(0, 64, 0)])
|
||||
|
||||
def test_gather_wood_job_keeps_existing_machine_sequence(self):
|
||||
job = JobStates(Munch())
|
||||
job = JobStates(Munch(yaw_target_override=90.0))
|
||||
self.assertIsNotNone(job.gather_wood_states)
|
||||
self.assertEqual(job.gather_wood(), [
|
||||
job.gather_wood_states,
|
||||
@@ -88,6 +88,7 @@ class GatherWoodPortTests(unittest.TestCase):
|
||||
job.stop()
|
||||
self.assertIs(job.gather_wood_states.state.__func__,
|
||||
job.gather_wood_states.idle.__func__)
|
||||
self.assertIsNone(job.g.yaw_target_override)
|
||||
|
||||
def test_grab_supplies_reads_protocol_777_container_shape(self):
|
||||
axe_id = next(iter(items.AXE_IDS))
|
||||
|
||||
Reference in new issue
Block a user