def set(self, items): deque.clear(self) if len(items) >= self._width: # restrict to required width self.extend(items[-self._width:]) else: # pad to required width self.extend(items + (None, ) * (self._width - 1 - len(items)))
def set(self, items): deque.clear(self) if len(items) >= self._width: # restrict to required width self.extend(items[-self._width:]) else: # pad to required width self.extend(items + (None,) * (self._width - 1 - len(items)))
def play_smart(self, screen): # self._update_screen(screen) # pygame.time.wait(5000) while not self.finished(): from collections import deque list_of_moves = [] deque = deque() if self._best_option() is not None: optimal_move_x = self._best_option()[0] optimal_move_y = self._best_option()[1] self.matrix[optimal_move_x][optimal_move_y].visited = True self.moves += 1 self._update_screen(screen) list_of_moves.append(self.matrix[optimal_move_x][optimal_move_y]) else: deque.clear() for element in self.list_of_hits: self.add_neighbours_deque(deque, element.x, element.y) while not self.finished() and len(deque) != 0: next_field = deque.pop() if next_field.ship_placed and not next_field.visited: self.hits += 1 self.list_of_hits.append(next_field) next_field.visited = True else: element.visited = True self._update_screen(screen) if self.finished(): return self.moves while not self.matrix[optimal_move_x][optimal_move_y].ship_placed: if self._best_option() is not None: optimal_move_x = self._best_option()[0] optimal_move_y = self._best_option()[1] list_of_moves.append(self.matrix[optimal_move_x][optimal_move_y]) self._update_screen(screen) self.matrix[optimal_move_x][optimal_move_y].visited = True self.moves += 1 self._update_screen(screen) self.hits += 1 self.add_neighbours_deque(deque, optimal_move_x, optimal_move_y) while not self.finished() and len(deque) != 0: next_field = deque.popleft() list_of_moves.append(next_field) if next_field.visited: continue if next_field.ship_placed and not next_field.visited: self.hits += 1 self.add_neighbours_deque(deque, next_field.x, next_field.y) self.moves += 1 next_field.visited = True self._update_screen(screen) return self.moves
def update_path_a(start_point, end_point, maze, deque): # get the shortest path using astar closest_path = astar.astar(start_point, end_point, maze) # starting point is not needed closest_path.remove(start_point) # if the current path has more points than the closest path by astar, # load the deque with the new set of points from a_star if len(deque) + 1 > len(closest_path): # clear the existing deque deque.clear() # append the new edges for edge in closest_path: deque.append(edge) # return the new deque return deque # if not, update the path as usual else: # return the deque with the appended path, end_point acts as the next point return update_path(end_point, deque)
def clear(): l = len(self) deque.clear(self) for i in range(0, l): self.__size_sema.acquire()
def clear(self): """Delete all file paths from the collection.""" deque.clear(self)
def clear(self): while (len(self)): self.outfp.write(output_single(self.popleft())) deque.clear(self)
numList = re.findall("\d+", str(input())) for j in range(len(numList)): deque.append(int(numList[j])) check = 0 for j in range(len(p)): if p[j] == 'R': if check == 0: check = 1 elif check == 1: check = 0 else: if deque: if check == 0: deque.popleft() elif check == 1: deque.pop() else: check = 2 print('error') break if check == 1: deque.reverse() if check != 2: print('[', end='') for j in range(len(deque) - 1): print(deque[j], end=',') if deque: print(deque[-1], end='') print(']') deque.clear()
def clear(self): while(len(self)): self.outfp.write(output_single(self.popleft())) deque.clear(self)
def clear(self): deque.clear(self) self.extend((None,) * self._width)
def clear(self): deque.clear(self) self.extend((None, ) * self._width)
def play_smart_v2(self, screen): while not self.finished(): from collections import deque list_of_moves = [] deque = deque() if self._best_option() is not None: optimal_move_x = self._best_option()[0] optimal_move_y = self._best_option()[1] self.matrix[optimal_move_x][optimal_move_y].visited = True self.moves += 1 self._update_screen(screen) list_of_moves.append(self.matrix[optimal_move_x][optimal_move_y]) else: deque.clear() for element in self.list_of_hits: self.add_neighbours_deque(deque, element.x, element.y) while not self.finished() and len(deque) != 0: next_field = deque.pop() if next_field.ship_placed and not next_field.visited: self.hits += 1 self.list_of_hits.append(next_field) next_field.visited = True else: element.visited = True self._update_screen(screen) if self.finished(): return self.moves while not self.matrix[optimal_move_x][optimal_move_y].ship_placed: if self._best_option() is not None: optimal_move_x = self._best_option()[0] optimal_move_y = self._best_option()[1] #print("uso", optimal_move_x, optimal_move_y) list_of_moves.append(self.matrix[optimal_move_x][optimal_move_y]) self._update_screen(screen) self.matrix[optimal_move_x][optimal_move_y].visited = True self.moves += 1 else: deque.clear() for element in self.list_of_hits: self.add_neighbours_deque(deque, element.x, element.y) while not self.finished() and len(deque) != 0: next_field = deque.pop() if next_field.ship_placed and not next_field.visited: self.hits += 1 self.list_of_hits.append(next_field) next_field.visited = True else: element.visited = True self._update_screen(screen) if self.finished(): return self.moves if self.finished(): return self.moves first_hit = self.matrix[optimal_move_x][optimal_move_y] self.list_of_hits.append(first_hit) self._update_screen(screen) self.hits += 1 self._add_vertical_neighbours_deque(deque, optimal_move_x, optimal_move_y) miss_counter = 0 tries = 0 while not self.finished() and miss_counter < 2 and len(deque) != 0: self.moves += 1 next_field = deque.popleft() list_of_moves.append(next_field) if next_field.visited: continue if next_field.ship_placed and not next_field.visited: self.hits += 1 self.list_of_hits.append(next_field) next_field.visited = True self._add_vertical_neighbours_deque(deque, next_field.x, next_field.y) self._update_screen(screen) else: miss_counter += 1 next_field.visited = True self._update_screen(screen) if tries <= 2: deque.clear() self._add_horizontal_neighbours_deque(deque, first_hit) miss_counter = 0 while not self.finished() and miss_counter < 2 and len(deque) != 0: next_field = deque.popleft() self.moves += 1 list_of_moves.append(next_field) if next_field.visited: continue if next_field.ship_placed and not next_field.visited: self.hits += 1 self.list_of_hits.append(next_field) next_field.visited = True self._add_horizontal_neighbours_deque(deque, next_field) self._update_screen(screen) else: miss_counter += 1 next_field.visited = True self._update_screen(screen) if self.hits == 16: deque.clear() for element in self.list_of_hits: self.add_neighbours_deque(deque, element.x, element.y) while not self.finished(): if len(deque) == 0: print(self.list_of_hits) break next_field = deque.pop() if next_field.ship_placed and not next_field.visited: self.hits += 1 self.list_of_hits.append(next_field) next_field.visited = True else: next_field.visited = True self._update_screen(screen) return self.moves