示例#1
0
    def to_commands(self):
        """Translate the assignments of ships to commands."""
        self.save_destinations(self.assignments)
        commands = []

        # Dropoff collisions.
        if self.allow_dropoff_collisions():
            self.resolve_dropoff_collisions(commands)

        # Assignment of next move.
        cost_matrix = self.create_cost_matrix()
        ships = [assignment.ship for assignment in self.assignments]
        row_ind, col_ind = LinearSum.assignment(cost_matrix,
                                                ships,
                                                cluster_mode=True)
        for k, i in zip(row_ind, col_ind):
            assignment = self.assignments[k]
            target = to_cell(i)
            commands.append(assignment.to_command(target))

        # Create dropoff assignments.
        for ship in self.dropoff_assignments:
            commands.append(ship.make_dropoff())

        return commands
示例#2
0
文件: MyBot.py 项目: stefank0/halite3
def new_want_to_spawn():
    """New implementation of want_to_spawn()."""
    turnremain = constants.MAX_TURNS - game.turn_number
    m = game_map.height * game_map.width
    halite = np.array([to_cell(i).halite_amount for i in range(m)])
    haliteremain = halite.sum()
    return (param['spawn_intercept'] +
            param['spawn_turnremain'] * turnremain +
            param['spawn_haliteremain'] * haliteremain) > 2000
示例#3
0
 def dropoff_ship(self):
     """Determine ship that creates the ghost dropoff."""
     for ship in self.ships:
         if ship.position == self.ghost.position:
             if (self.me.halite_amount < self.dropoff_cost(ship)
                     or to_cell(to_index(ship)).has_structure):
                 return None
             return ship
     return None
示例#4
0
    def best_position(self, indices):
        """Determine the best position.

        Note:
            Returns None if a good position was not found. If that is the case,
            the GhostDropoff should not be considered any further.
        """
        if not indices:
            return None
        best_index = min(indices, key=self.cost)
        if self.cost(best_index) == 0.0:
            return None
        return to_cell(best_index).position
示例#5
0
 def assignment(self, ships):
     """Assign destinations to ships using an assignment algorithm."""
     cost_matrix = self.create_cost_matrix(ships)
     row_ind, col_ind = LinearSum.assignment(cost_matrix, ships)
     for i, j in zip(row_ind, col_ind):
         ship = ships[i]
         best_average_halite = -1.0 * cost_matrix[i, j]
         if not self.valuable(ship, best_average_halite):
             self.assign_kamikaze(ship)
         elif (ship.halite_amount > 550
               and self._return_average_halite(ship) > best_average_halite):
             self.assign_return(ship)
         else:
             destination = to_cell(j).position
             self.schedule.assign(ship, destination)
示例#6
0
 def cost(self, index):
     """Cost representing the quality of the index as a dropoff location."""
     if to_cell(index).has_structure:
         return 0.0
     modifier = self._disputed_factor(index) * self._expansion_factor(index)
     return -1.0 * modifier * self.map_data.halite_density[index]