def get_potential_dropoffs(input_game): mean_halite_at_all_locations = [] for x in range(input_game.game_map.width): for y in range(input_game.game_map.height): position = Position(x, y) halite = input_game.game_map[position].halite_amount cardinals = position.get_surrounding_cardinals() for cardinal in cardinals: halite += input_game.game_map[cardinal].halite_amount mean = halite/5.0 mean_halite_at_all_locations.append((position, mean)) mean_halite_at_all_locations.sort(key=by_halite, reverse=True) dropoffs = mean_halite_at_all_locations[:10] return dropoffs
def navigate(ship, target): ''' takes a ship and its target destination. (Position) return a direction. if it can move towards to direction it will. if it can't move and can stay still it will. if it can't move towards it and can't stay still it will randomly move to a safe location. if none of these is possible it will stay still and die. ''' global position_choices unsafe_moves = game_map.get_unsafe_moves(ship.position, target) shuffle(unsafe_moves) move = None for unsafe_move in unsafe_moves: unsafe_position = [ x + y for x, y in zip(unsafe_move, [ship.position.x, ship.position.y]) ] unsafe_position = game_map.normalize(Position(*unsafe_position)) if unsafe_position not in position_choices: move = unsafe_move break if move == None: if ship.position not in position_choices: move = Direction.Still else: cardinals = Position.get_surrounding_cardinals(ship.position) for cardinal in cardinals: if cardinal not in position_choices: x = cardinal.x - ship.position.x y = cardinal.y - ship.position.y move = list_to_direction([x, y]) break if move == None: logging.info(f'Ship {ship.id} will Die') move = Direction.Still return move
# it's a table not a set cleared_path = [[False for y in range(height)] for x in range(width)] # contains tuples of (x,y) path_queue = set( normalize_position(entity.position) for entity in chain([me.shipyard], me.get_dropoffs())) # end = time.time() # logging.info("PreFindAdjacent\t" + str(round((end - start) * 1000))) while len(path_queue) != 0: x, y = path_queue.pop() cleared_path[x][y] = True p = Position(x=x, y=y) # if game_map.calculate_distance(p, me.shipyard.position) < 10: # why not for u in p.get_surrounding_cardinals(): u_x, u_y = normalize_position(u) if game_map[u].halite_amount <= low_threshold: if not cleared_path[u_x][u_y]: path_queue.add((u_x, u_y)) else: adjacent_cells.add((u_x, u_y)) # end = time.time() # logging.info("PostFindMax\t" + str(round((end - start) * 1000))) l_adjacent_cells = list(adjacent_cells) ##################################################### # exploring ships will target adjacent cells and avoid cleared_path