def test_puddle_world_calculates_transition_with_multiple_slow_puddles( self): # This world has 2 circular ⚫️ slow puddles centered in the middle # of the arena. One had a radius of 0.25, and the other 0.1. We expect # that as we move through the larger one, we will be slowed to # 0.5 times base speed, and as we move through both we will be slowed to # 0.25 times base speed. 🐌 pw = puddle_world.PuddleWorld( puddles=(puddle_world.SlowPuddle( shape=puddle_world.circle(geometry.Point((0.5, 0.5)), 0.25)), puddle_world.SlowPuddle( shape=puddle_world.circle(geometry.Point(( 0.5, 0.5)), 0.1))), goal_position=geometry.Point((0.5, 0.5)), noise=0.0, thrust=0.5) # A large thrust to step over multiple circles. start_position = geometry.Point((0.2, 0.5)) transition = pw.transition(start_position, puddle_world.Action.RIGHT) # 0.5 total movement 🏃 # 0.05 spent getting to first circle's edge. # 0.3 spent getting to second circle's edge. # 0.15 remaining at 25% efficiency => 0.0375 into inner circle. expected_end_position = geometry.Point((0.4375, 0.5)) self.assertEqual(transition.state, start_position) self.assertPointsAlmostEqual(transition.next_state, expected_end_position)
def test_slow_puddle_uses_movement_as_expected(self, start_point, end_point, expected_end_point, multiplier=0.5): shape = rectangle(geometry.Point((0.0, 0.0)), geometry.Point( (1.0, 1.0))) wall = puddle_world.SlowPuddle(shape, multiplier) new_end_point = wall.update_transition_end_point( start_point, end_point) self.assertAlmostEqual(new_end_point, expected_end_point)
def test_puddle_world_correctly_applies_wall_puddles(self): pw = puddle_world.PuddleWorld( puddles=(puddle_world.SlowPuddle( shape=puddle_world.circle(geometry.Point((0.5, 0.5)), 0.25)), puddle_world.WallPuddle( shape=puddle_world.circle(geometry.Point(( 0.5, 0.5)), 0.1))), goal_position=geometry.Point((0.5, 0.5)), noise=0.0, thrust=0.5) # A large thrust to step over multiple circles. start_position = geometry.Point((0.2, 0.5)) transition = pw.transition(start_position, puddle_world.Action.RIGHT) # We should stop at the inner wall puddle. expected_end_position = geometry.Point((0.4, 0.5)) self.assertEqual(transition.state, start_position) self.assertPointsAlmostEqual(transition.next_state, expected_end_position)
"""PuddleWorld arenas.""" import frozendict from shapely import geometry from aux_tasks.puddle_world import puddle_world # Repeated shapes _TOP_WALL = geometry.Polygon(((0.4, 1.0), (0.4, 0.6), (0.6, 0.6), (0.6, 1.0))) _BOTTOM_WALL = geometry.Polygon( ((0.4, 0.0), (0.4, 0.4), (0.6, 0.4), (0.6, 0.0))) EMPTY = () HYDROGEN = ( puddle_world.SlowPuddle( puddle_world.circle(geometry.Point((0.5, 0.5)), 0.3)), puddle_world.SlowPuddle( puddle_world.circle(geometry.Point((0.5, 0.5)), 0.15)), ) SUTTON = ( puddle_world.SlowPuddle( geometry.LineString([(0.1, 0.75), (0.45, 0.75)]).buffer(0.1)), puddle_world.SlowPuddle( geometry.LineString([(0.45, 0.4), (0.45, 0.8)]).buffer(0.1)), ) TWO_ROOM = ( puddle_world.WallPuddle(_TOP_WALL), puddle_world.WallPuddle(_BOTTOM_WALL), )