def get_worms_in_range(self): """ Returns a list of coordinates with worms in shooting range Takes into account if there are any obstacles in the way. If there is an obstacle, the worm is seen as not in range. """ max_range = self.current_worm_info['weapon']['range'] current_x = self.current_worm_info['position']['x'] current_y = self.current_worm_info['position']['y'] cells_in_range = [] for opponent in self.enemy_info: for w in opponent['worms']: worm = w['position'] dist = np.floor( distance.euclidean([worm['x'], worm['y']], [current_x, current_y])) if dist <= max_range: direction = get_cardinal_direction([current_x, current_y], [worm['x'], worm['y']]) obstacles = self.check_for_obstacles_in_path( [current_x, current_y], [worm['x'], worm['y']], direction) if (direction is None) or (obstacles is True): continue else: cells_in_range.append( [worm['x'], worm['y'], direction]) return cells_in_range
def get_augmented_map(self): """ 1. Calculates the distance to every cell from current cell. 2. Checks the cardinal direction for cell with reference to current cell. 3. Removes all cells that are 'DEEP_SPACE', since these cannot be interacted with. Returns a dataframe of self.flattened_map with additional columns ['x','y','type',''Distance', 'Direction'] """ augmented_map = [] current_x = self.current_worm_info['position']['x'] current_y = self.current_worm_info['position']['y'] for cell in self.flattened_map: cell_distance = int( np.floor( distance.euclidean([cell.x, cell.y], [current_x, current_y]))) direction = get_cardinal_direction([current_x, current_y], [cell.x, cell.y]) augmented_map.append( AugmentedCell(cell.x, cell.y, cell.type, cell_distance, direction)) return augmented_map