Example #1
0
    def test_falling_from_board(self):

        with captured_output() as (out, err):
            robot = Robot(4, 4, "east")
            robot.move()

        output = out.getvalue().strip()
        self.assertEqual(output,
                         "Safety warning - I am about to fall to oblivion!")
Example #2
0
    def execute_path_exploration(self, path, goal_pos):
        _output_string = []

        _temp_block = path.pop()

        _ori_target = None

        _temp_robot = Robot(self._robot.get_pos(), False)
        _temp_robot.set_ori(self._robot.get_ori())
        _temp_robot.set_speed(0)

        while _temp_robot.get_pos()[0] != goal_pos[0] or _temp_robot.get_pos(
        )[1] != goal_pos[1]:
            if _temp_robot.get_pos()[0] == _temp_block.get_pos(
            )[0] and _temp_robot.get_pos()[1] == _temp_block.get_pos()[1]:
                _temp_block = path.pop()

            _ori_target = self.get_target_ori(_temp_robot.get_pos(),
                                              _temp_robot.get_ori(),
                                              _temp_block)

            _action = None
            if _temp_robot.get_ori() != _ori_target:
                _action = self.get_target_move(_temp_robot.get_ori(),
                                               _ori_target)
            else:
                _action = Action.FORWARD

            print('Action {} from {} to {}'.format(_action.value,
                                                   _temp_robot.get_pos(),
                                                   _temp_block.get_pos()))
            _temp_robot.move(_action)
            self._actions.append(_action)
            _output_string.append(_action.value)

        for _act in self._actions:
            if _act == Action.FORWARD:
                if not self.can_move_forward():
                    print("Fastest Path Execution terminated!")
                    return "T"

            self._robot.move(_act)
            self._robot.notify(_act.value, self._map, True)

            self._robot.set_sensor()
            self._robot.sense(self._map)  #, self._real_map)
            if self._surface is not None:
                self._map.draw(self._surface)

        return ''.join(_output_string)