Example #1
0
    def on_game_start(self, config):
        """
        Read in config and perform any initial setup here
        """
        gamelib.debug_write("Configuring your custom algo strategy...")
        self.config = config
        global WALL, SUPPORT, TURRET, SCOUT, DEMOLISHER, INTERCEPTOR, MP, SP 
        
        WALL = config["unitInformation"][0]["shorthand"]
        SUPPORT = config["unitInformation"][1]["shorthand"]
        TURRET = config["unitInformation"][2]["shorthand"]
        SCOUT = config["unitInformation"][3]["shorthand"]
        DEMOLISHER = config["unitInformation"][4]["shorthand"]
        INTERCEPTOR = config["unitInformation"][5]["shorthand"]
        MP = 1
        SP = 0

        global HOME_FIELD, OPP_SIDE, SCORE_LOC, DEPLOY_LOC, mp_threshold
        HOME_FIELD = self.get_my_grid()
        OPP_SIDE =  self.get_opp_grid()
        SCORE_LOC = self.get_scoring_locs()
        DEPLOY_LOC = self.get_deploy_loc()
        self.is_attacking = False
        self.attacking_round_start = -1
        self.attacking_right = False
        mp_threshold = 8

        # This is a good place to do initial setup
        self.scored_on_locations = []
        self.damaged_locs = []
        self.REINFORCE_MID = False

        self.enemy_units = [[], [], [], [], [], [], [], []]
        self.BEGIN = True
        self.DEMOLISHER = False
        self.last_demolisher_run = 0
        # Used for the support logic
        self.support_locations = []

        for i in range(14, 11, -1):
            # for j in range(5, 2, -1):
            for j in range(5, 3, -1):
                self.support_locations.append([i, j])
        
        self.built_supports = []
        self.upgraded_supports = []
Example #2
0
 def on_game_start(self, config):
     """
     Read in config and perform any initial setup here
     """
     gamelib.debug_write('Configuring your custom algo strategy...')
     self.config = config
     global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER, BITS, CORES
     FILTER = config["unitInformation"][0]["shorthand"]
     ENCRYPTOR = config["unitInformation"][1]["shorthand"]
     DESTRUCTOR = config["unitInformation"][2]["shorthand"]
     PING = config["unitInformation"][3]["shorthand"]
     EMP = config["unitInformation"][4]["shorthand"]
     SCRAMBLER = config["unitInformation"][5]["shorthand"]
     BITS = 1
     CORES = 0
     # This is a good place to do initial setup
     self.scored_on_locations = []
 def on_turn(self, turn_state):
     """
     This function is called every turn with the game state wrapper as
     an argument. The wrapper stores the state of the arena and has methods
     for querying its state, allocating your current resources as planned
     unit deployments, and transmitting your intended deployments to the
     game engine.
     """
     start_time = time.time()
     game_state = gamelib.GameState(self.config, turn_state)
     gamelib.debug_write('Performing turn {} of your custom algo strategy'.format(game_state.turn_number))
     game_state.suppress_warnings(True)  # Comment or remove this line to enable warnings.
     self.evaluate_self_defence(game_state)
     self.evaluate_enemy_defence(game_state)
     self.populate_defense(game_state, [13], start_time)
     self.__place__attackers__(game_state, start_time)
     game_state.submit_turn()
 def on_game_start(self, config):
     """ 
     Read in config and perform any initial setup here 
     """
     gamelib.debug_write('Configuring your custom algo strategy...')
     self.config = config
     global WALL, SUPPORT, TURRET, SCOUT, DEMOLISHER, INTERCEPTOR, MP, SP
     WALL = config["unitInformation"][0]["shorthand"]
     SUPPORT = config["unitInformation"][1]["shorthand"]
     TURRET = config["unitInformation"][2]["shorthand"]
     SCOUT = config["unitInformation"][3]["shorthand"]
     DEMOLISHER = config["unitInformation"][4]["shorthand"]
     INTERCEPTOR = config["unitInformation"][5]["shorthand"]
     MP = 1
     SP = 0
     # This is a good place to do initial setup
     self.scored_on_locations = []
Example #5
0
    def prioritize_action(self, id: str) -> None:
        """
        Moves an action to the front of the priority queue by id
        """
        index = -1
        for i, entry in enumerate(self.action_queue):
            if entry['id'] == id:
                index = i
                break

        if index == -1:
            debug_write("[DEBUG] cannot prioritize nonexistant action:", id)
            raise ValueError('Cannot prioritize nonexistant action')

        self.change_flag = True
        value = self.action_queue.pop(index)
        self.action_queue.insert(0, value)
    def on_turn(self, turn_state):
        """
        This function is called every turn with the game state wrapper as
        an argument. The wrapper stores the state of the arena and has methods
        for querying its state, allocating your current resources as planned
        unit deployments, and transmitting your intended deployments to the
        game engine.
        """
        game_state = gamelib.GameState(self.config, turn_state)
        gamelib.debug_write(
            'Performing turn {} of your custom algo strategy'.format(
                game_state.turn_number))
        # game_state.suppress_warnings(True)  #Uncomment this line to suppress warnings.

        self.starter_strategy(game_state)

        game_state.submit_turn()
Example #7
0
    def on_game_start(self, config):
        """ 
        Read in config and perform any initial setup here 
        """
        gamelib.debug_write("Configuring your custom algo strategy...")
        self.config = config
        global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER, BITS, CORES
        FILTER = config["unitInformation"][0]["shorthand"]
        ENCRYPTOR = config["unitInformation"][1]["shorthand"]
        DESTRUCTOR = config["unitInformation"][2]["shorthand"]
        PING = config["unitInformation"][3]["shorthand"]
        EMP = config["unitInformation"][4]["shorthand"]
        SCRAMBLER = config["unitInformation"][5]["shorthand"]
        BITS = 1
        CORES = 0
        # This is a good place to do initial setup
        self.scored_on_locations = []

        Units = namedtuple("Units",
                           "FILTER ENCRYPTOR DESTRUCTOR PING EMP SCRAMBLER")
        self.units = Units(FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER)

        # Assume right side is vulnerable
        self.is_right_opening = True
        self.filter_locs = [
            [0, 13],
            [1, 13],
            [5, 13],
            [6, 13],
            [7, 13],
            [8, 13],
            [9, 13],
            [11, 13],
            [12, 13],
            [13, 13],
            [14, 13],
            [15, 13],
            [16, 13],
            [18, 13],
            [19, 13],
            [20, 13],
            [21, 13],
            [22, 13],
            [26, 13],
            [27, 13],
        ]
 def __init__(self):
     super().__init__()
     seed = random.randrange(maxsize)
     random.seed(seed)
     gamelib.debug_write('Random seed: {}'.format(seed))
     self.grid_map = []
     j_start = 13
     j_end = 15
     for i in range(0, 14):
         self.grid_map.append([0] * (j_end - j_start))
         j_start -= 1
         j_end += 1
     j_start = 0
     j_end = 28
     for i in range(14, 28):
         self.grid_map.append([0] * (j_end - j_start))
         j_start += 1
         j_end -= 1
Example #9
0
    def were_corners_attacked(self, curr_state, prev_state):
        """ Checks if corners were attacked in the last round.

        :param curr_state: state object.
        :param prev_state: state object.
        """
        left_damage, right_damage = 0, 0

        if not self.R_CORNER_ATTACKED:
            right_damage = max(0, self.check_corner(curr_state, prev_state, self.RIGHT_CORNER_MASK))
            debug_write("Right damage ", right_damage)

        if not self.L_CORNER_ATTACKED:
            left_damage = max(0, self.check_corner(curr_state, prev_state, self.LEFT_CORNER_MASK))
            debug_write("Left damage ", left_damage)

        self.R_CORNER_ATTACKED = right_damage > self.CORNER_DAMAGE_THRESH
        self.L_CORNER_ATTACKED = left_damage > self.CORNER_DAMAGE_THRESH
Example #10
0
 def on_game_start(self, config):
     """ 
     Read in config and perform any initial setup here 
     """
     gamelib.debug_write('Configuring your custom algo strategy...')
     self.config = config
     global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER
     FILTER = config["unitInformation"][0]["shorthand"]
     ENCRYPTOR = config["unitInformation"][1]["shorthand"]
     DESTRUCTOR = config["unitInformation"][2]["shorthand"]
     PING = config["unitInformation"][3]["shorthand"]
     EMP = config["unitInformation"][4]["shorthand"]
     SCRAMBLER = config["unitInformation"][5]["shorthand"]
     self.cores = 0
     self.bits = 0
     self.scored_on_locations = dict()
     self.damaged_on_locations = dict()
     self.sp = False
Example #11
0
 def build_first_round(self, game_state):
     """
     Set up first round
     """
     gamelib.debug_write('Turn[{}] build_first_round() - start'.format(
         game_state.turn_number))
     for location in self.init_destructor:
         if game_state.can_spawn(DESTRUCTOR, location):
             game_state.attempt_spawn(DESTRUCTOR, location)
     for location in self.init_middle_destructor:
         if game_state.can_spawn(DESTRUCTOR, location):
             game_state.attempt_spawn(DESTRUCTOR, location)
     for location in self.init_flower:
         uplocation = [location[0], location[1] + 1]
         if not game_state.contains_stationary_unit(
                 uplocation) and not location in self.open_location_right:
             if game_state.can_spawn(ENCRYPTOR, location):
                 game_state.attempt_spawn(ENCRYPTOR, location)
Example #12
0
 def on_game_start(self, config):
     self.turnNum = 0
     gamelib.debug_write('Configuring your custom algo strategy...')
     self.config = config
     global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER
     FILTER = config["unitInformation"][0]["shorthand"]
     ENCRYPTOR = config["unitInformation"][1]["shorthand"]
     DESTRUCTOR = config["unitInformation"][2]["shorthand"]
     PING = config["unitInformation"][3]["shorthand"]
     EMP = config["unitInformation"][4]["shorthand"]
     SCRAMBLER = config["unitInformation"][5]["shorthand"]
     self.scored_on_locations = []
     self.destructorLocations = [[3,12],[24,12],[8,9],[19,9],[12,9],[15,9]]
     self.filterLocations = [[ 0, 13],[ 1, 13],[ 2, 13],[ 3, 13],[ 4, 13],[ 23, 13],[ 24, 13],[ 25, 13],[ 26, 13],[ 27, 13],[ 4, 12],[ 23, 12],[ 4, 11],[ 23, 11],[ 5, 10],[ 7, 10],[ 8, 10],[ 9, 10],[ 11, 10],[ 12, 10],[ 15, 10],[ 16, 10],[ 18, 10],[ 19, 10],[ 20, 10],[ 22, 10],[ 6, 9],[ 7, 9],[ 9, 9],[ 10, 9],[ 11, 9],[ 16, 9],[ 17, 9],[ 18, 9],[ 20, 9],[ 21, 9]]
     self.spawnLoc = [22,8]
     self.scramSpawn = [[22,8],[5,8]]
     self.encryptLoc = [[ 11, 7],[ 12, 7],[ 13, 7],[ 14, 7],[ 15, 7],[ 16, 7],[ 12, 6],[ 13, 6],[ 14, 6],[ 15, 6],[ 12, 5],[ 13, 5],[ 14, 5],[ 15, 5]]
     self.encryptorCount = 0
Example #13
0
    def starter_strategy(self, game_state):
        """
        For defense we will use a spread out layout and some Scramblers early on.
        We will place destructors near locations the opponent managed to score on.
        For offense we will use long range EMPs if they place stationary units near the enemy's front.
        If there are no stationary units to attack in the front, we will send Pings to try and score quickly.
        """
        # First, place basic defenses
        self.build_defences(game_state)
        # Now build reactive defenses based on where the enemy scored
        # self.build_reactive_defense(game_state)

        self.attack(game_state)

        self.enemy_health_overtime.append(game_state.enemy_health)

        gamelib.debug_write('enemy health last time was {}'.format(
            self.enemy_health_overtime))
    def __init__(self):
        super().__init__()
        seed = random.randrange(maxsize)
        random.seed(seed)
        gamelib.debug_write('Random seed: {}'.format(seed))

        # Locations passed by reference to GameState. Should only be updated in GameState
        self.turret_locations = []
        self.wall_locations = []
        self.support_locations = []

        # Fake gamestate creation support
        self.remove_loc_check = []
        for j in range(13, -1, -1):
            for i in range(13-j, 15+j):
                self.remove_loc_check.append([i, j])

        self.enemy_attack_predictor = GaussianNB()
Example #15
0
 def complete_requests(self,
                       game_state,
                       request_list,
                       max_priority=math.inf):
     for request in request_list:
         # gamelib.debug_write(request)
         if (game_state.get_resource(CORES) <
                 self.cores_to_keep) or (request[3] > max_priority):
             return
         if request[0] == 0:
             # gamelib.debug_write(f"Running game_state.can_spawn({request[1]}, {request[2]})")
             if game_state.can_spawn(request[1], request[2]):
                 game_state.attempt_spawn(request[1], request[2])
                 gamelib.debug_write("Number of cores left: " +
                                     str(game_state.get_resource(CORES)) +
                                     " \n")
         elif request[0] == 1:
             game_state.attempt_upgrade(request[2])
Example #16
0
    def on_turn(self, turn_state):
        """
        This function is called every turn with the game state wrapper as
        an argument. The wrapper stores the state of the arena and has methods
        for querying its state, allocating your current resources as planned
        unit deployments, and transmitting your intended deployments to the
        game engine.
        """
        game_state = gamelib.AdvancedGameState(self.config, turn_state)

        if game_state.turn_number == 0:
            while game_state.can_spawn(PING, self.firstTurnTroopCoord):
                game_state.attempt_spawn(PING, self.firstTurnTroopCoord)
            # no building this turn
        else:
            left_corner_stats = game_state.get_area_stats(
                self.enemy_left_corner_area)
            gamelib.debug_write(
                'left_corner_stats = {}'.format(left_corner_stats))
            right_corner_stats = game_state.get_area_stats(
                self.enemy_left_corner_area)
            gamelib.debug_write(
                'right_corner_stats = {}'.format(right_corner_stats))

            if game_state.get_resource(game_state.BITS) >= 8:
                self.readyToAttack = True
            else:
                self.readyToAttack = False

            # determine which side is more vulnerable
            if left_corner_stats.destructor_count < right_corner_stats.destructor_count:
                self.SetSideToAttack(Sides.LEFT, game_state)
            else:
                self.SetSideToAttack(Sides.RIGHT, game_state)

            if self.readyToAttack:
                if self.useRammingTroops:
                    self.deployRammingTroops(game_state)
                self.deployTroops(game_state)

            self.buildWalls(game_state)
            self.markForRefund(game_state)

        game_state.submit_turn()
Example #17
0
    def build_the_wall(self, game_state):
        filters_built = 0
        encryptors_built = 0
        destructors_built = 0
        gamelib.debug_write('Building wall')

        # Adding left side corner shield
        destructors_built += game_state.attempt_spawn(
            DESTRUCTOR, self.get_line_points([0, 13], [2, 13]))
        # Adding right side corner shield
        destructors_built += game_state.attempt_spawn(
            DESTRUCTOR, self.get_line_points([25, 13], [27, 13]))

        # Adding V of power
        # First, putting down two destructors on each side
        # [5,10] [8,7]
        destructors_built += game_state.attempt_spawn(DESTRUCTOR,
                                                      ([5, 10], [8, 7]))
        # [19, 7] [22, 10]
        destructors_built += game_state.attempt_spawn(DESTRUCTOR,
                                                      ([19, 7], [22, 10]))
        # Then, draw lines of encryptors
        encryptors_built += game_state.attempt_spawn(
            ENCRYPTOR, self.get_line_points([2, 13], [10, 5]))
        encryptors_built += game_state.attempt_spawn(
            ENCRYPTOR, self.get_line_points([17, 5], [25, 13]))

        # Building the channel
        encryptors_built += game_state.attempt_spawn(ENCRYPTOR, [11, 5])
        encryptors_built += game_state.attempt_spawn(ENCRYPTOR, [16, 5])
        destructors_built += game_state.attempt_spawn(
            DESTRUCTOR, ([12, 4], [12, 5], [15, 4], [15, 5]))

        # Shields for destructors
        # filters_built += game_state.attempt_spawn(
        #     DESTRUCTOR, [[12, 4], [15, 4]])
        # filters_built += game_state.attempt_spawn(
        #     DESTRUCTOR, [[11, 5], [12, 5]])
        # filters_built += game_state.attempt_spawn(
        #     DESTRUCTOR, [[15, 5], [16, 5]])
        gamelib.debug_write("Built " + str(destructors_built) + "D " +
                            str(encryptors_built) + "E")

        return filters_built
Example #18
0
    def on_game_start(self, config):
        """
        Read in config and perform any initial setup here
        """
        gamelib.debug_write('Configuring your custom algo strategy...')
        self.config = config
        global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER, BARREL_MASK, BARREL_MASK_IDX, BASE_PASSIVE_LOCS
        self.filter, self.encryptor, self.destructor, \
        self.ping, self.emp, self.scrambler = [i for i in range(6)]

        FILTER = config["unitInformation"][0]["shorthand"]
        ENCRYPTOR = config["unitInformation"][1]["shorthand"]
        DESTRUCTOR = config["unitInformation"][2]["shorthand"]
        PING = config["unitInformation"][3]["shorthand"]
        EMP = config["unitInformation"][4]["shorthand"]
        SCRAMBLER = config["unitInformation"][5]["shorthand"]

        BARREL_MASK = [
            # Destructors
            [23, 13],
            [24, 13],
            # Encryptors
            [23, 12],
            [24, 12],
            [25, 13],
            [23, 11],
            # Filters
            [1, 13],
            [1, 12],
            [0, 13],
            [18, 10],
            [18, 11],
            [13, 11],
            [9, 10],
            [9, 11],
            [5, 11],
        ]
        BARREL_MASK_IDX = {
            "destructors": (0, 2),
            "encryptors": (2, 6),
            "filters": (6, 15)
        }
        BASE_PASSIVE_LOCS = [[3, 12], [10, 10], [17, 8]]
        self.prev_state = None
Example #19
0
    def on_turn(self, turn_state):
        #____LOOP______
        #____NEEDED____
        game_state = gamelib.GameState(self.config, turn_state)
        gamelib.debug_write(
            'Performing turn {} of your custom algo strategy'.format(
                game_state.turn_number))
        game_state.suppress_warnings(True)
        #______________

        FILTER_DEPLOY_LOCATION = [[0, 13], [1, 13], [2, 13], [3, 13], [4, 13],
                                  [5, 13], [6, 13], [7, 13], [8, 13], [9, 13],
                                  [10, 13], [17, 13], [18, 13], [19, 13],
                                  [20, 13], [21, 13], [22, 13], [23, 13],
                                  [24, 13], [25, 13], [26, 13], [27, 13]]
        ENCRYPTOR_DEPLOY_LOCATION = [[10, 11], [17, 11], [10, 10], [17, 10],
                                     [4, 9], [5, 9], [6, 9], [7, 9], [8, 9],
                                     [9, 9], [18, 9], [19, 9], [20, 9],
                                     [21, 9], [22, 9], [23, 9]]
        DESTRUCTOR_DEPLOY_LOCATION = [[1, 12], [4, 12], [7, 12], [10, 12],
                                      [17, 12], [20, 12], [23, 12], [26, 12],
                                      [10, 9], [17, 9]]
        UNITBLOCK_DEPLOY_LOCATION = [[11, 13], [16, 13], [11, 12], [16, 12],
                                     [11, 11], [16, 11], [11, 10], [16, 10],
                                     [11, 9], [16, 9], [5, 8], [6, 8], [7, 8],
                                     [8, 8], [9, 8], [10, 8], [11, 8], [16, 8],
                                     [17, 8], [18, 8], [19, 8], [20, 8],
                                     [21, 8], [22, 8]]

        #[[ 5, 8],[ 22, 8],[ 6, 7],[ 21, 7]]
        if game_state.turn_number % 2:
            self.deploy_information(game_state, [5, 8], SCRAMBLER, 2)
            self.deploy_information(game_state, [6, 7], EMP, 1)
        else:
            self.deploy_information(game_state, [22, 8], SCRAMBLER, 2)
            self.deploy_information(game_state, [21, 7], EMP, 1)

        self.deploy_fireWall(game_state, UNITBLOCK_DEPLOY_LOCATION, FILTER)
        self.deploy_fireWall(game_state, DESTRUCTOR_DEPLOY_LOCATION,
                             DESTRUCTOR)
        self.deploy_fireWall(game_state, FILTER_DEPLOY_LOCATION, FILTER)
        self.deploy_fireWall(game_state, ENCRYPTOR_DEPLOY_LOCATION, ENCRYPTOR)

        game_state.submit_turn()
    def on_action_frame(self, turn_string):
        """
        This is the action frame of the game. This function could be called
        hundreds of times per turn and could slow the algo down so avoid putting slow code here.
        Processing the action frames is complicated so we only suggest it if you have time and experience.
        Full doc on format of a game frame at: https://docs.c1games.com/json-docs.html
        """
        # Let's record at what position we get scored on
        state = json.loads(turn_string)
        events = state["events"]
        breaches = events["breach"]

        P2 = 2

        frame = state['turnInfo'][2]
        for attack in events['attack']:
            # first attack by enemy ping or emp
            if attack[6] == P2 and (attack[3] == 3 or attack[3] == 4) and attack[4] not in self.unit_counted:
                # onto player's left side
                if attack[1][1] <= 13 and attack[1][0] <= 13 and frame // 8 < len(self.attacks_on_frame):
                    self.attacks_on_frame[frame // 8] += 1
                    self.unit_counted[attack[4]] = True
        if len(events['spawn']) > 0:
            spent = 0
            for spawn in events['spawn']:
                if spawn[3] == P2:
                    if spawn[1] == 3: spent += 1
                    if spawn[1] == 4: spent += 3
            if spent >= self.MIN_BITS_SPENT_ATTACK:
                self.bits_to_enemy_attack[self.enemy_bits] = True
            else:
                self.bits_to_enemy_attack[self.enemy_bits] = False


        for breach in breaches:
            location = breach[0]
            unit_owner_self = True if breach[4] == 1 else False
            # When parsing the frame data directly,
            # 1 is integer for yourself, 2 is opponent (StarterKit code uses 0, 1 as player_index instead)
            if not unit_owner_self:
                gamelib.debug_write("Got scored on at: {}".format(location))
                self.scored_on_locations.append(location)
                gamelib.debug_write("All locations: {}".format(self.scored_on_locations))
Example #21
0
    def on_turn(self, turn_state):
        """
        This function is called every turn with the game state wrapper as
        an argument. The wrapper stores the state of the arena and has methods
        for querying its state, allocating your current resources as planned
        unit deployments, and transmitting your intended deployments to the
        game engine.
        """
        game_state = gamelib.AdvancedGameState(self.config, turn_state)

        gamelib.debug_write('Performing turn {} of your custom algo strategy'.format(game_state.turn_number))
        game_state.suppress_warnings(True)  #Uncomment this line to suppress warnings.

        # Perform setup if the turn number is zero
        # Check if we should move up our setup, or not.
        if game_state.turn_number == 0:
            self.initial_setup(game_state)
            return

        '''
        OVERARCHING STRATEGY LOGIC
            If getting rushed --> Defend and rush other side
            If they have a solid defence --> Build escort strategy
            If they have a dumb opening --> Rush them
            If the game is super passive --> Build encryptors and defend
        '''

        # Patch up any holes in our defences
        self.reactive_defence()

        # Check if we want to rush them, if so, then do it!
        rush_loc, rush_unit = self.find_rush_spot(game_state)
        if rush_loc is not None:
            self.attack_hole(game_state, rush_loc, rush_unit)
            game_state.submit_turn()
            return

        # The idea is that they will constantly update defences. Find out what their heavy side
        # is, and determine if we should go escort or not
        heavy_side = self.scan_opponent_defences(game_state)
        self.escort_strategy(game_state, heavy_side)

        game_state.submit_turn()
Example #22
0
    def on_game_start(self, config):
        """ 
        Read in config and perform any initial setup here 
        """
        gamelib.debug_write('Configuring your custom algo strategy...')
        self.config = config
        global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER
        FILTER = config["unitInformation"][0]["shorthand"]
        ENCRYPTOR = config["unitInformation"][1]["shorthand"]
        DESTRUCTOR = config["unitInformation"][2]["shorthand"]
        PING = config["unitInformation"][3]["shorthand"]
        EMP = config["unitInformation"][4]["shorthand"]
        SCRAMBLER = config["unitInformation"][5]["shorthand"]
        # This is a good place to do initial setup
        self.scored_on_locations = []

        self.attack_stage = 0
        self.attack_config = [
        ]  # (direction, attack_type, attack_num, support)
Example #23
0
    def build_defenses(self,
                       location_list,
                       firewall_unit,
                       game_state,
                       row=None):
        for location in location_list:
            if not type(location) == list:
                location = [location, row]

            if game_state.can_spawn(firewall_unit, location):
                game_state.attempt_spawn(firewall_unit, location)
                gamelib.debug_write(f"{firewall_unit} deployed at {location}")
                game_state._player_resources[0][
                    'cores'] -= game_state.type_cost(firewall_unit)

            elif not game_state.contains_stationary_unit(location):
                return False

        return True
Example #24
0
    def __init__(self):
        super().__init__()
        seed = random.randrange(maxsize)
        random.seed(seed)
        gamelib.debug_write('Random seed: {}'.format(seed))
        # a = np.ones((10,1))
        # b = np.ones((10,1))
        # c = np.sum(a * b, axis=0)
        # gamelib.debug_write('numpy test: {}'.format(c))

        a = torch.randn(2, 2)
        a = ((a * 3) / (a - 1))
        gamelib.debug_write(a.requires_grad)
        a.requires_grad_(True)
        gamelib.debug_write(a.requires_grad)
        b = (a * a).sum()
        gamelib.debug_write(b.grad_fn)
        b.backward()
        gamelib.debug_write(a.grad)
Example #25
0
 def on_game_start(self, config):
     """
     Read in config and perform any initial setup here
     """
     gamelib.debug_write('Configuring your custom algo strategy...')
     self.config = config
     global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER
     FILTER = config["unitInformation"][0]["shorthand"]
     ENCRYPTOR = config["unitInformation"][1]["shorthand"]
     DESTRUCTOR = config["unitInformation"][2]["shorthand"]
     PING = config["unitInformation"][3]["shorthand"]
     EMP = config["unitInformation"][4]["shorthand"]
     SCRAMBLER = config["unitInformation"][5]["shorthand"]
     # Batch ping threshold
     self.batch_ping_num = 10
     # If we sent out our ping batch last round
     self.sent_pings_last_round = False
     # Enemy health before we sent out our last ping batch
     self.enemy_health_before_attack = 30
Example #26
0
    def stall_with_scramblers(self, game_state):
        for loc in list(self.scored_on_locations):
            gamelib.debug_write("Scrambler Location: {}".format(loc))

            # send a scrambler for every 3 enemy num of bits
            num_scramblers = (int)(game_state.get_resource(BITS, 1)) // 4 + 1
            gamelib.debug_write("NumScrams: {}".format(num_scramblers))
            if num_scramblers > 3:
                num_scramblers = 3
            for i in range(0, num_scramblers):
                while loc[1] >= 11:
                    x, y = loc
                    if loc[0] > loc[1]:
                        x -= 1
                        y -= 1
                    if loc[1] > loc[0]:
                        x += 1
                        y -= 1
                game_state.attempt_spawn(SCRAMBLER, [x, y])
Example #27
0
    def deploy_attackers(self, game_state):
        """
        if (game_state.turn_number == 0 and game_state.can_spawn(EMP, [25, 11])) or RIGHT_SIDE_EMERGENCY:
            game_state.attempt_spawn(EMP, [25, 11])
        
        
        if game_state.number_affordable(PING) > 4 and game_state.can_spawn(SCRAMBLER, [5,8]):
	        game_state.attempt_spawn(SCRAMBLER,[5,8])
        """
        while game_state.get_resource(
                game_state.BITS) >= game_state.type_cost(PING):
            #gamelib.debug_write('resources for PINGS...')
            if game_state.can_spawn(PING, [14, 0]):
                game_state.attempt_spawn(PING, [14, 0])
            else:
                gamelib.debug_write(
                    '{} Bits cant spawn PINGS at [14,0]'.format(
                        game_state.turn_number))
                return
    def on_game_start(self, config):
        """
        Read in config and perform any initial setup here
        """
        gamelib.debug_write('Configuring your custom algo strategy...')
        self.config = config
        global FILTER, ENCRYPTOR, DESTRUCTOR, PING, EMP, SCRAMBLER
        self.filter, self.encryptor, self.destructor, self.ping, self.emp, self.scrambler = [i for i in range(6)]
        FILTER = config["unitInformation"][0]["shorthand"]
        ENCRYPTOR = config["unitInformation"][1]["shorthand"]
        DESTRUCTOR = config["unitInformation"][2]["shorthand"]
        PING = config["unitInformation"][3]["shorthand"]
        EMP = config["unitInformation"][4]["shorthand"]
        SCRAMBLER = config["unitInformation"][5]["shorthand"]

        self.unique_locs = []
        self.emp_num = 0
        self.defences = Defences(config)
        self.prev_state = None
    def stall_with_scramblers(self, game_state):
        for loc in list(self.scored_on_locations):
            gamelib.debug_write("Scrambler Location: {}".format(loc))

            # send a scrambler for every 3 enemy num of bits
            num_scramblers = (int)(game_state.get_resource(BITS, 1)) // 4 + 1
            gamelib.debug_write("NumScrams: {}".format(num_scramblers))
            if num_scramblers > 3:
                num_scramblers = 3
            for i in range(0, num_scramblers):
                # Build destructor one space above so that it doesn't block our own edge spawn locations
                while loc[1] >= 11:
                    if loc[0] > loc[1]:
                        loc[0] -= 1
                        loc[1] -= 1
                    if loc[1] > loc[0]:
                        loc[0] += 1
                        loc[1] -= 1
                game_state.attempt_spawn(SCRAMBLER, [loc[0], loc[1]])
    def starter_strategy(self, game_state):
        

        self.build_defences(game_state)

        #TODO better heuristic for seeing if firing is worthwhile... do real tracking ... can help us fire earlier too
        ping_count  = game_state.get_resource(BITS)//1;
        bit_increment = (game_state.turn_number // 10) + 5
        ping_spawn_location_options = [[11, 2], [16, 2]]

        if self.can_ping(game_state, ping_count, ping_spawn_location_options) and self.ENEMY_HEALTH-ping_count < 5 and self.ENEMY_HEALTH-ping_count > 0:
            gamelib.debug_write("Stalling")
        elif self.can_ping(game_state, ping_count, ping_spawn_location_options) and ping_count > 12:
            best_location = self.least_damage_spawn_location(game_state, ping_spawn_location_options)
            game_state.attempt_spawn(PING, best_location, 1000);
        elif not self.can_ping(game_state, ping_count, ping_spawn_location_options):
            if ping_count > 18:     
                best_location = self.least_damage_spawn_location(game_state, ping_spawn_location_options)
                game_state.attempt_spawn(EMP, best_location, 1000);