コード例 #1
0
ファイル: enemyTarget.py プロジェクト: En3rG/HaliteIII
    def move_ships(self):
        print_heading("Populate Enemy targets......")
        for ship_id in (self.data.mySets.ships_all
                        & self.data.mySets.ships_to_move):
            self.populate_heap(ship_id)

        while self.heap_explore:
            s = heapq.heappop(self.heap_explore)

            ## OLD WAY (MARK TAKEN)
            #explore_destination = self.isDestination_untaken(s)
            ## NEW WAY
            explore_destination = self.isDestination_updated(s)

            if s.ship_id in self.data.mySets.ships_to_move and explore_destination:
                logging.debug(s)
                self.data.myDicts.snipe_ship.setdefault(s.ship_id, None)
                self.data.myDicts.snipe_ship[s.ship_id] = s
                self.data.myLists.snipe_target.append(
                    Target(s.ratio, s.ship_id, s.destination, s.matrix_ratio))

                ## OLD WAY (MARK TAKEN)
                #self.mark_taken_udpate_top_halite(explore_destination)
                ## NEW WAY (DEDUCT HALITE TO BE HARVESTED)
                self.update_harvest_matrix(s.ship_id, explore_destination)
コード例 #2
0
ファイル: harvest.py プロジェクト: En3rG/HaliteIII
    def move_ships(self):
        print_heading("Moving harvesting (now) ships......")
        ## MOVE SHIPS (THAT WILL HARVEST NOW)
        for target in self.data.myLists.explore_target:
            ship_id = target.ship_id
            ship = self.data.game.me._ships.get(ship_id)

            if ship_id in self.data.mySets.ships_to_move:
                explore_destination = target.destination

                canHarvest, harvest_direction = self.check_harvestNow(
                    ship_id, moveNow=False)

                directions = self.get_directions_target(
                    ship, explore_destination)
                explore_direction = self.best_direction(ship,
                                                        directions,
                                                        mode=MoveMode.EXPLORE)

                harvest_destination = self.get_destination(
                    ship, harvest_direction)
                harvest_ratio = target.matrix_ratio[harvest_destination.y][
                    harvest_destination.x]

                if canHarvest and -target.ratio < harvest_ratio * self.data.myVars.harvest_ratio_to_explore:
                    destination = harvest_destination
                    direction = harvest_direction

                    self.mark_taken_udpate_top_halite(destination)
                    self.move_mark_unsafe(ship, direction)
コード例 #3
0
ファイル: getInitData.py プロジェクト: En3rG/HaliteIII
    def __init__(self, game):
        super().__init__(game)

        print_heading("Gathering Initialized data......")

        self.unavailable_area = np.zeros(
            (game.game_map.height, game.game_map.width), dtype=np.float16)
        self.update_matrix()
コード例 #4
0
ファイル: exploreTarget.py プロジェクト: En3rG/HaliteIII
    def move_ships(self):
        print_heading("Populate Explore targets and depositing ships......")

        self.update_harvest_matrix_moved_ships()

        self.populate_all_heap()

        self.gather_target_ships()

        self.gather_deposit_ships()
コード例 #5
0
    def move_ships(self):
        print_heading("Moving build (dock) ships......")

        allowBuild = self.data.game.turn_number <= constants.MAX_TURNS * MyConstants.build.allowed_turns \
                                 and self.data.myVars.ratio_left_halite > MyConstants.build.stop_when_halite_left \
                                 and len(self.data.mySets.ships_all) > MyConstants.build.min_num_ships

        if allowBuild:
            self.building_now()
            self.building_later()
            self.go_towards_building()
コード例 #6
0
    def move_ships(self):
        print_heading("Moving exploring ships......")

        for target in self.data.myLists.explore_target:
            ship_id = target.ship_id
            ship = self.data.game.me._ships.get(ship_id)

            if ship_id in self.data.mySets.ships_to_move:
                explore_destination = target.destination

                canHarvest, harvest_direction = self.check_harvestNow(
                    ship_id, moveNow=False)
                # if not(canHarvest): canHarvest, harvest_direction = self.check_harvestLater(ship_id,
                #                                                                             MyConstants.DIRECTIONS,
                #                                                                             kicked=False,
                #                                                                             moveNow=False)

                directions = self.get_directions_target(
                    ship, explore_destination)
                ## OLD WAY
                explore_direction = self.best_direction(ship,
                                                        directions,
                                                        mode=MoveMode.EXPLORE)
                ## USING ASTAR
                #explore_direction = self.get_Astar_direction(ship, explore_destination, directions)

                harvest_destination = self.get_destination(
                    ship, harvest_direction)
                harvest_ratio = target.matrix_ratio[harvest_destination.y][
                    harvest_destination.x]

                if canHarvest and -target.ratio < harvest_ratio * self.data.myVars.harvest_ratio_to_explore:
                    destination = harvest_destination
                    direction = harvest_direction
                else:
                    destination = explore_destination
                    direction = explore_direction

                logging.debug(
                    "explore_destination {} -s.ratio {} harvest_destination {} harvest_ratio {}"
                    .format(explore_destination, -target.ratio,
                            harvest_destination, harvest_ratio))

                if direction == Direction.Still and self.data.myMatrix.locations.myDocks[
                        ship.position.y][ship.position.x] == Matrix_val.ONE:
                    ## IF STILL AND AT A DOCK (MOVE!!)
                    move_kicked_ship(self, ship,
                                     all_directions=True)  ## NOT REALLY KICKED
                else:
                    #self.mark_taken_udpate_top_halite(destination)
                    self.move_mark_unsafe(ship, direction)
コード例 #7
0
    def check_retreat(self):
        """
        POPULATE HEAP BASED ON DISTANCE FROM SHIPYARD/DOCKS
        CHECK IF WE NEED TO START RETREATING BACK
        """
        print_heading("Check retreat......")

        self.populate_heap()

        logging.debug("Farthest ship is {}, with {} turns left".format(
            self.farthest_ship, self.turns_left))

        if self.farthest_ship.distance + MyConstants.retreat.extra_turns > self.turns_left:
            self.move_ships()
コード例 #8
0
def spawn_ships(data):
    """
    CHECK IF ITS SAFE TO SPAWN SHIPS

    -BELOW STOP SPAWNING PERCENTAGE
    -HAVE ENOUGH HALITE TO BUILD
    -NOT BUILDING DOCKS
    -SHIPYARD NOT OCCUPIED
    -NO SHIP GOING TO SHIPYARD

    :param data:
    """
    ## NEW WAY USING DEPLETION TIME
    # depletion_time = get_time_of_depletion(data)
    #
    # allowSpawn = data.game.turn_number <= constants.MAX_TURNS * MyConstants.spawn.min_turn_percent or \
    #              (data.game.turn_number <= constants.MAX_TURNS * MyConstants.spawn.max_turn_percent
    #               and depletion_time > constants.MAX_TURNS
    #               and data.myVars.ratio_left_halite > MyConstants.spawn.stop_halite_left)

    ## NEWER WAY (KEEP BUILDING IF BELOW THE ENEMY)
    numMyShips = data.myDicts.players_info[data.game.me.id].num_ships
    numEnemyShips, enemyID = min([
        (v.num_ships, k) for k, v in data.myDicts.players_info.items()
        if k != data.game.me.id
    ])  ## LOWEST ENEMY SHIPS NUMBER
    ## KEEP MAKING SHIPS AS LONG AS ITS BELOW THE THRESHOLD TURNS
    ## AND WE HAVE MORE MONEY THAN LOWEST ENEMY
    ## AND WE HAVE LESS SHIPS THAN THE LOWEST ENEMY
    logging.debug("allowSpawn nummyships {} numenemyships {} ratio {}".format(
        numMyShips, numEnemyShips,
        numMyShips <= numEnemyShips * MyConstants.spawn.percent_more_ships))
    allowSpawn = data.game.turn_number <= constants.MAX_TURNS * data.myVars.max_allowed_turn \
                  and ( data.myVars.ratio_left_halite > MyConstants.spawn.stop_halite_left
                        #or numMyShips < numEnemyShips * MyConstants.spawn.percent_more_ships)
                        or ( len(data.game.players) == 2) and numMyShips < numEnemyShips * MyConstants.spawn.percent_more_ships )

    shipyard = data.game.game_map[data.game.me.shipyard]
    if allowSpawn \
            and data.myVars.isSaving == False \
            and data.game.me.halite_amount >= constants.SHIP_COST \
            and data.myMatrix.locations.safe[shipyard.position.y][shipyard.position.x] != Matrix_val.UNSAFE:
        # and not data.game.game_map[data.game.me.shipyard].is_occupied\                                            ## NOT ACCURATE? LOOKS AT CURRENT TURN BUT SPAWN HAPPENS NEXT TURN

        print_heading("Safe to spawn ship......")
        data.halite_stats.record_spent(BuildType.SHIP)
        command = data.game.me.shipyard.spawn()
        data.command_queue.append(command)
コード例 #9
0
ファイル: stuck.py プロジェクト: En3rG/HaliteIII
    def move_ships(self):
        print_heading("Moving stuck ships......")

        self.build_on_high_halite()

        ## MOVE SHIPS THAT CANNOT MOVE YET
        for ship_id in (self.data.mySets.ships_all
                        & self.data.mySets.ships_to_move):
            ship = self.data.game.me._ships.get(ship_id)

            if self.data.myMatrix.locations.stuck[ship.position.y][
                    ship.position.x] == Matrix_val.ONE:
                logging.debug(
                    "Ship id: {} has not enough halite to move".format(
                        ship.id))
                self.move_mark_unsafe(ship, Direction.Still)
コード例 #10
0
    def __init__(self, game, init_data, prev_data, halite_stats):
        super().__init__(game)

        print_heading("Gathering data......")

        self.prev_data = prev_data
        self.halite_stats = halite_stats
        self.init_data = init_data
        self.command_queue = []
        self.starting_halite = init_data.myVars.total_halite
        self.count_ships_died(
        )  ## RECORD DROPPED HALITE, BASED ON SHIPS THAT DIED

        logging.debug("All ships [{} total]: {}".format(
            len(self.mySets.ships_all), self.mySets.ships_all))

        self.update_matrix()

        self.get_rate_of_decay()
コード例 #11
0
ファイル: attack.py プロジェクト: En3rG/HaliteIII
    def move_ships(self):
        print_heading("Moving attack ships......")

        allowAttack = (constants.MAX_TURNS * MyConstants.attack.allowed_turns_lower_limit <= self.data.game.turn_number <= constants.MAX_TURNS * MyConstants.attack.allowed_turns_upper_limit) \
                           and len(self.data.mySets.ships_all) > MyConstants.attack.min_ships_before_attacking

        ## MOVE SHIPS CLOSEST TO ENEMY FIRST (WITH ITS SUPPORT SHIP)
        if allowAttack:
            considered_prev_i = OrderedSet(
            )  ## USED TO NOT CONSIDER PREVIOUS i

            for i in range(
                    1, MyConstants.attack.engage_enemy_distance
            ):  ## DONT NEED TO MOVE FURTHEST ONES (WILL BE MOVED AS SUPPORT)
                matrixIDs = self.data.myMatrix.locations.engage_enemy[
                    i] * self.data.myMatrix.locations.myShipsID
                r, c = np.where(matrixIDs > Matrix_val.ZERO)
                ships_engaging = OrderedSet(
                    self.data.myMatrix.locations.myShipsID[
                        r, c]) - considered_prev_i
                ships_attacking = ships_engaging & self.data.mySets.ships_to_move
                considered_prev_i.update(ships_attacking)
                self.considered_already.update(ships_attacking)

                logging.debug("i {} ships_attacking {}".format(
                    i, ships_attacking))

                self.heap_kamikaze = []
                self.heap_support = []  ## RESET PER ITERATION

                for ship_id in sorted(ships_attacking):
                    self.populate_heap(ship_id, i)

                ## MOVE ATTACK/SUPPORT SHIPS
                self.move_attack_suppport()

                ## MOVE KAMIKAZE SHIPS
                self.move_kamikaze()
コード例 #12
0
ファイル: deposit.py プロジェクト: En3rG/HaliteIII
    def move_ships(self):
        print_heading("Moving depositing ships......")

        for id in self.data.mySets.deposit_ships:
            while self.data.mySets.ships_kicked:
                ship_kicked = self.data.mySets.ships_kicked.pop()
                logging.debug(
                    "Moving kicked ship ({}) by a depositing ship".format(
                        ship_kicked))
                ship = self.data.game.me._ships.get(ship_kicked)
                if ship.id in self.data.mySets.ships_to_move:
                    self.data.mySets.ships_to_move.remove(ship.id)

                move_kicked_ship(self, ship)

            ship = self.data.game.me._ships.get(id)
            s = self.data.myDicts.deposit_ship[id]

            if ship.id in self.data.mySets.ships_to_move:
                self.data.mySets.ships_to_move.remove(ship.id)
                self.depositNow(ship,
                                s.dock_position,
                                s.directions,
                                harvest_home=True)
コード例 #13
0
ファイル: MyBot.py プロジェクト: En3rG/HaliteIII
    ## GET EACH SHIP'S TARGET
    M = ExploreTarget(data, prev_data)
    N = EnemyTarget(data, prev_data)

    R = Deposit(data, prev_data)

    ## HARVEST SHIPS
    H = Harvest(data, prev_data)

    ## ATTACK SHIPS
    P = Attack(data, prev_data)

    ## EXPLORE SHIPS
    I = Explore(data, prev_data)

    ## SPAWN SHIPS
    J = spawn_ships(data)

    game.end_turn(data.command_queue)

    ## SAVE DATA TO PREV DATA
    #prev_data = copy.deepcopy(data)  ## TAKES 300ms, AND COPYING A LOT OF UNNECESSARY STUFF
    prev_data = copy.deepcopy(PrevData(data))

    ## UPDATE HALITE AMOUNT/CARRIED
    halite_stats.set_halite(game, data)

    ## PRINT HALITE STATS
    print_heading("Halite Stats: {}".format(halite_stats))