Exemple #1
0
class ReleaseStrategy:
    def __init__(self):
        self.__first_move = True

    def __lazy_init(self, context: Context):
        self.__stuck = StuckDetector(
            history_size=150,
            stuck_distance=min(context.me.width, context.me.height),
            unstack_distance=max(context.me.width, context.me.height) * 1.5,
        )
        self.__direction = DirectionDetector(
            begin=context.position,
            end=context.position + context.direction,
            min_distance=max(context.me.width, context.me.height),
        )
        self.__controller = Controller(distance_to_wheels=context.me.width / 4)
        self.__move_mode = AdaptiveMoveMode(
            start_tile=context.tile,
            controller=self.__controller,
            get_direction=self.__direction,
            speed_angle_to_direct_proportion=(
                BUGGY_INITIAL_ANGLE_TO_DIRECT_PROPORTION
                if context.is_buggy
                else JEEP_INITIAL_ANGLE_TO_DIRECT_PROPORTION
            ),
        )

    @property
    def path(self):
        return self.__move_mode.path

    @property
    def target_position(self):
        return self.__move_mode.target_position

    def move(self, context: Context):
        context.move.engine_power = 1
        if context.world.tick < context.game.initial_freeze_duration_ticks:
            return
        if self.__first_move:
            self.__lazy_init(context)
            self.__first_move = False
        if context.me.durability > 0:
            self.__stuck.update(context.position)
        else:
            self.__stuck.reset()
        self.__direction.update(context.position)
        if self.__stuck.positive_check():
            self.__move_mode.switch()
            self.__stuck.reset()
            self.__controller.reset()
            self.__direction.reset(begin=context.position,
                                   end=context.position + context.direction)
        elif not self.__move_mode.is_forward and self.__stuck.negative_check():
            self.__move_mode.use_forward()
            self.__stuck.reset()
            self.__controller.reset()
            self.__direction.reset(begin=context.position,
                                   end=context.position + context.direction)
        self.__move_mode.move(context)
Exemple #2
0
 def __lazy_init(self, context: Context):
     self.__stuck = StuckDetector(
         history_size=150,
         stuck_distance=min(context.me.width, context.me.height),
         unstack_distance=max(context.me.width, context.me.height) * 1.5,
     )
     self.__direction = DirectionDetector(
         begin=context.position,
         end=context.position + context.direction,
         min_distance=max(context.me.width, context.me.height),
     )
     self.__controller = Controller(distance_to_wheels=context.me.width / 4)
     self.__move_mode = AdaptiveMoveMode(
         start_tile=context.tile,
         controller=self.__controller,
         get_direction=self.__direction,
         speed_angle_to_direct_proportion=(
             BUGGY_INITIAL_ANGLE_TO_DIRECT_PROPORTION
             if context.is_buggy
             else JEEP_INITIAL_ANGLE_TO_DIRECT_PROPORTION
         ),
     )
Exemple #3
0
 def test_start_direct_backward_with_initial_speed(self):
     controller = Controller(distance_to_wheels=1)
     result = controller(
         course=Point(-1, 0),
         angle=0,
         direct_speed=Point(-1, 0),
         angular_speed_angle=0,
         engine_power=0,
         wheel_turn=0,
         target_speed=Point(-1, 0),
         tick=0,
         backward=False,
     )
     assert_that(result.engine_power, equal_to(-1))
     assert_that(result.wheel_turn, equal_to(0))
     assert_that(result.brake, equal_to(False))
Exemple #4
0
 def test_start_right(self):
     controller = Controller(distance_to_wheels=1)
     result = controller(
         course=Point(0, 1),
         angle=0,
         direct_speed=Point(0, 0),
         angular_speed_angle=0,
         engine_power=0,
         wheel_turn=0,
         target_speed=Point(0, 1),
         tick=0,
         backward=False,
     )
     assert_that(result.engine_power, equal_to(1))
     assert_that(result.wheel_turn, greater_than(0))
     assert_that(result.brake, equal_to(False))
Exemple #5
0
 def test_start_direct_backward_with_initial_opposite_speed_turn_left(self):
     controller = Controller(distance_to_wheels=1)
     result = controller(
         course=Point(-1, -0.1),
         angle=0,
         direct_speed=Point(1, 0),
         angular_speed_angle=0,
         engine_power=0,
         wheel_turn=0,
         target_speed=Point(-1, -0.1),
         tick=0,
         backward=True,
     )
     assert_that(result.engine_power, equal_to(-1))
     assert_that(result.wheel_turn, less_than(0))
     assert_that(result.brake, equal_to(True))