Best Python code snippet using autotest_python
board_env.py
Source:board_env.py  
...67        else:68            self.num_steps_same = 069        self.prev_reward = reward; 70        return reward 71    def stop_if_necessary(self):72        if self.num_steps_same >= MAX_AIMLESS_WANDERING:73            print("Episode ended due to aimless wandering")74            self.num_steps_same = 075            return True76        return False77        78    def step(self, action):79        self.move_if_appropriate(action)80        81        ob = self.create_state()82        episode_over = False83        reward = self.process_reward()84        if self.replay_counter == 0: #never end episode during experience replay85            episode_over = reward > self.done_percentage86            episode_over = self.stop_if_necessary()87        self.should_replay_and_setup()88        if episode_over:89            self.saved_robot_state = []90            self.saved_world_state = []91        return ob, reward, episode_over, {}92    #sets up replay and determines whether to replay93    def should_replay_and_setup(self):94        #start a replay counter 95        if len(self.saved_world_state) > LENGTH_REPLAY and self.replay_counter == 0 and random.random() < P_REPLAY:96            self.replay_counter =197            self.replay_world_states, self.replay_robot_states = self.random_state_batch(LENGTH_REPLAY)98            print("Started replay")99            return True100        if self.replay_counter >= LENGTH_REPLAY:...LightShow.py
Source:LightShow.py  
...15        self.stop_time = stop_time16        self.process = None17        self._should_stop = False18    def __del__(self):19        self.stop_if_necessary()20    def start(self):21        assert self.is_stopped(), "Cannot start the process while it is already running."22        self._should_stop = False23        self.process = threading.Thread(target=self.run)24        self.process.start()25    def stop(self):26        assert not self.is_stopped(), "Cannot stop the process -- it has not been started."27        self._should_stop = True28        self.process = None29    def is_stopped(self):30        return self.process is None31    def stop_if_necessary(self):32        if self.process is not None:33            self.stop()34    def run(self):35        overt = 1000 * self.transition_time36        c = 037        while True:38            if self._should_stop:39                break40            for light in self.lights:41                light.turn_on(self.colors[c], overt)42                c += 143                c %= len(self.colors)44            c += 145            c %= len(self.colors)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
