Esempio n. 1
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.
        """
        # TODO: remove advanced state from function signatures if we initialize it here already.
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        game_state.suppress_warnings(
            True)  # Uncomment this line to suppress warnings.

        self.build_barrel(game_state)
        self.shoot(game_state)

        damaged_locations = self._find_damaged_def_units(game_state)
        if damaged_locations:
            self.build_reactive_defence(game_state, damaged_locations)

        self.build_passive_defence(game_state)

        # Must run at the very end of the algo.
        self.prev_state = copy.deepcopy(game_state)
        game_state.submit_turn()
    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.

        emp_cheese = True if self.emp_num > 1 and len(self.unique_locs) == 1 else False
        if emp_cheese:
            d, f = self.can_block(self.unique_locs[0], copy.deepcopy(turn_state))
        self.defences.build_template(game_state, self.prev_state, emp_cheese)
        self.prev_state = copy.deepcopy(game_state)

        if game_state.turn_number != 0:
            try:
                self.best_spawn(game_state)
            except Exception:
                self.attack(game_state)

        game_state.submit_turn()
 def get_destructors_on_path(self, game_state, start_point, end_points):
     path = gamelib.ShortestPathFinder.navigate_multiple_endpoints(
         start_point, end_points, game_state)
     adv_game_state = gamelib.AdvancedGameState(game_state)
     retval = 0
     for location in path:
         attackers = adv_game_state.get_attackers(location, 0)
         retval = retval + len(attackers)
     return retval
Esempio n. 4
0
    def on_turn(self, cmd):
        '''
        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, cmd)
        gamelib.debug_write('Performing turn {} of your custom algo strategy'.format(game_state.turn_number))

        self.starter_strategy(game_state)

        game_state.submit_turn()
Esempio n. 5
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.

        self.defend(game_state)
        self.attack(game_state)
        game_state.submit_turn()
Esempio n. 6
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        #p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))

        if game_state.turn_number != 0:
            if p2UnitCount < 8:
                self.attackForMaxPain(game_state)
            else:
                self.attackForMaxDestruction(game_state)

            self.reinforceBreachLocation(game_state)

        self.breach_list = []
        game_state.submit_turn()
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        #p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(
            self.jsonState.get('p2Units')[1]) + len(
                self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))

        shouldRebuild = game_state.turn_number > 7
        needsStrongerCorners = game_state.turn_number > 3

        self.buildFirewalls(game_state, self.cornerTowers, DESTRUCTOR,
                            shouldRebuild)
        if needsStrongerCorners:
            self.buildFirewalls(game_state, self.cornerFilters, DESTRUCTOR,
                                shouldRebuild)
        else:
            self.buildFirewalls(game_state, self.cornerFilters, FILTER,
                                shouldRebuild)
        self.buildFirewalls(game_state, self.lightHouseTowers, DESTRUCTOR,
                            shouldRebuild)
        self.reinforceDestructors(game_state, self.lightHouseTowers,
                                  shouldRebuild)
        self.buildFirewalls(game_state, self.filterWall, FILTER, shouldRebuild)
        self.buildFirewalls(game_state, self.tunnelTowers, DESTRUCTOR,
                            shouldRebuild)
        self.buildFirewalls(game_state, self.cornerPhaseTwo, FILTER,
                            shouldRebuild)
        self.buildFirewalls(game_state, self.encryptorPhaseOne, ENCRYPTOR,
                            False)
        self.buildFirewalls(game_state, self.row_ten, DESTRUCTOR, False)
        self.buildFirewalls(game_state, self.encryptorPhaseTwo, ENCRYPTOR,
                            False)

        if self.attackWithPings:
            if game_state.number_affordable(
                    PING) >= 8 + (game_state.turn_number // 10):
                self.attackForMaxPain(game_state)
                if game_state.turn_number > 4:
                    self.attackWithPings = False
        else:
            if game_state.number_affordable(
                    EMP) > 2 + (game_state.turn_number // 18):
                self.attackForMaxDestruction(game_state)
                self.attackWithPings = True

        game_state.submit_turn()
Esempio n. 8
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)
        p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0])
        #gamelib.debug_write('p1 has {} units. p2 has {} units'.format(p1UnitCount, p2UnitCount))

        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_right_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()
Esempio n. 9
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()
Esempio n. 10
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        #p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(self.jsonState.get('p2Units')[1]) + len(self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))
        
        shouldRebuild = game_state.turn_number > 7
        needsStrongerCorners = game_state.turn_number > 3            

        self.buildFirewalls(game_state, self.mainTowers, DESTRUCTOR, False)
        self.buildFirewalls(game_state, self.filterWall, FILTER, False)
        self.buildFirewalls(game_state, self.extraCornerTower, DESTRUCTOR, False)
        self.buildFirewalls(game_state, self.frontWall, FILTER, False)
        self.buildFirewalls(game_state, self.encryptors, ENCRYPTOR, False)

        
        while game_state.can_spawn(EMP, [24, 10]):
            game_state.attempt_spawn(EMP, [24, 10])
        

        game_state.submit_turn()
Esempio n. 11
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        #p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))

        self.reinforceBreachLocation(game_state)

        # line detection #
        firstRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.FIRST_ENEMY_ROW)
        secondRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.SECOND_ENEMY_ROW)
        thirdRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.THIRD_ENEMY_ROW)
        fourthRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.FOURTH_ENEMY_ROW)
        gamelib.debug_write('row counts: {},{},{},{}'.format(
            firstRowDefenderCount, secondRowDefenderCount,
            thirdRowDefenderCount, fourthRowDefenderCount))

        if firstRowDefenderCount > 8:
            self.mirrorEnemy(game_state, game_state.game_map.FIRST_ENEMY_ROW)
        elif secondRowDefenderCount > 6:
            self.mirrorEnemy(game_state, game_state.game_map.SECOND_ENEMY_ROW)
        elif thirdRowDefenderCount > 6:
            self.mirrorEnemy(game_state, game_state.game_map.THIRD_ENEMY_ROW)
        elif fourthRowDefenderCount > 6:
            self.mirrorEnemy(game_state, game_state.game_map.FOURTH_ENEMY_ROW)

        if game_state.turn_number != 0:
            if p2UnitCount < 8:
                self.attackForMaxPain(game_state)
            else:
                self.attackForMaxDestruction(game_state)

        self.breach_list = []
        game_state.submit_turn()
    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.
        """

        #if not first turn, parse last turn's action phase strings
        if self.game_state is not None:
            self.parse_action_phase()

        self.__action_strings = []

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

        self.starter_algo(self.game_state)

        self.game_state.submit_turn()
Esempio n. 13
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        p1UnitCount = len(self.jsonState.get('p1Units')[0]) + len(self.jsonState.get('p1Units')[1]) + len(self.jsonState.get('p1Units')[2])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(self.jsonState.get('p2Units')[1]) + len(self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))
        gamelib.debug_write('p2 army cost last turn = {}'.format(self.enemy_army_cost))
        
        if self.army_dict.get('total_cost', 0) > 0:
            self.lastEnemyArmyDict = self.army_dict.copy()
        
        if 'total_cost' in self.lastEnemyArmyDict and game_state.get_resource(game_state.BITS, 1) >= self.lastEnemyArmyDict['total_cost']:
            gamelib.debug_write('I predict that p2 will spawn an army this turn!')
        
        shouldRebuild = game_state.turn_number > 3
        shouldRebuildWall = p1UnitCount >= 27 #only reinforce if the full wall is in place
        needsStrongerCorners = game_state.turn_number > 3      
        towersToBuild = 1   
        self.coresToSpendOnRebuilding = 4

        if game_state.turn_number == 0:
            self.buildFirewalls(game_state, self.filterCorners, FILTER, False)
            self.buildFirewalls(game_state, self.turnZeroTowers, DESTRUCTOR, False)
            #game_state.attempt_spawn(EMP, self.turnZeroEMPCoord)
            #game_state.attempt_spawn(SCRAMBLER, self.turnZeroScramblerCoord)

        else:
            if game_state.turn_number == 1:
                self.shieldEMPs = False
                # copy game_state twice, build left and right door and see which provides more targets
                # consider making a full line across to see how many targets are in range?
                # with the goal of maximizing the targets safe to hit from behind our wall??
                # That might be enough to beat George?
                # Also, add more weight to high-value targets, if we can safely take out DESTRUCTORs, do it!!
                game_state_try_left = copy.deepcopy(game_state)
                self.buildFirewalls(game_state_try_left, self.leftDoorTowers, DESTRUCTOR, False, 3)
                self.buildFirewalls(game_state_try_left, self.leftDoorFilters, FILTER, False)
                leftValue = self.attackForMaxDestruction(game_state_try_left)

                game_state_try_right = copy.deepcopy(game_state)
                self.buildFirewalls(game_state_try_right, self.rightDoorTowers, DESTRUCTOR, False, 3)
                self.buildFirewalls(game_state_try_right, self.rightDoorFilters, FILTER, False)
                rightValue = self.attackForMaxDestruction(game_state_try_right)

                gamelib.debug_write("leftValue = {}, rightValue = {}".format(leftValue, rightValue))

                self.useRightDoor = (rightValue > leftValue)
                if self.useRightDoor:
                    self.reservedCoords.append([2, 12])
                    self.reservedCoords.append([2, 13])
                else:
                    self.reservedCoords.append([25, 12])
                    self.reservedCoords.append([25, 13])
                towersToBuild = 3

            self.threatenSpawn(game_state)

            if game_state.turn_number >= 2 and not self.earlyEncryptorBuilt:
                if game_state.number_affordable(ENCRYPTOR) > 0:
                    self.earlyEncryptorBuilt = True
                if self.useRightDoor:
                    game_state.attempt_spawn(ENCRYPTOR, [6, 9])
                else:
                    game_state.attempt_spawn(ENCRYPTOR, [21, 9])

            # if we've been breached in the corner, strengthen it!
            if [27, 13] in self.breach_list:
                self.buildFirewalls(game_state, [[26, 12]], DESTRUCTOR, True)
                self.buildFirewalls(game_state, [[26, 13]], FILTER, True)
            if [0, 13] in self.breach_list:
                self.buildFirewalls(game_state, [[1, 12]], DESTRUCTOR, True)
                self.buildFirewalls(game_state, [[1, 13]], FILTER, True)

            self.buildFirewalls(game_state, self.filterCorners, FILTER, shouldRebuild)
            self.buildFirewalls(game_state, self.turnZeroTowers, DESTRUCTOR, shouldRebuild)
            if self.useRightDoor:
                self.buildFirewalls(game_state, self.rightDoorTowers, DESTRUCTOR, shouldRebuildWall, towersToBuild)
                self.buildFirewalls(game_state, self.rightDoorFilters, FILTER, shouldRebuildWall)
                self.buildFirewalls(game_state, self.rightExtraCornerTower, DESTRUCTOR, False)
                self.buildFirewalls(game_state, self.rightRearHallway, FILTER, False)
                self.buildFirewalls(game_state, [[22, 8]], ENCRYPTOR, False)
                # the front wall might be fruitless - if the same things are getting destoryed
                # over and over, it would probably do better to build encryptors to break the stalemate
                # could even finance it by selling the rear hallway.
                self.buildFirewalls(game_state, self.rightFrontWall, FILTER, False)
                self.buildFirewalls(game_state, self.rightEncryptors, ENCRYPTOR, False)
            else:
                self.buildFirewalls(game_state, self.leftDoorTowers, DESTRUCTOR, shouldRebuildWall, towersToBuild)
                self.buildFirewalls(game_state, self.leftDoorFilters, FILTER, shouldRebuildWall)
                self.buildFirewalls(game_state, self.leftExtraCornerTower, DESTRUCTOR, False)
                self.buildFirewalls(game_state, self.leftRearHallway, FILTER, False)
                self.buildFirewalls(game_state, [[5, 8]], ENCRYPTOR, False)
                # the front wall might be fruitless - if the same things are getting destoryed
                # over and over, it would probably do better to build encryptors to break the stalemate
                # could even finance it by selling the rear hallway.
                self.buildFirewalls(game_state, self.leftFrontWall, FILTER, False)
                self.buildFirewalls(game_state, self.leftEncryptors, ENCRYPTOR, False)
                        
            if game_state.turn_number == 1 or game_state.turn_number > 5:
                copy_of_game_state = copy.deepcopy(game_state)
                risk = self.attackForMaxPain(copy_of_game_state)
                if risk == 0:
                    self.attackForMaxPain(game_state)
            
            # we may need to counter their troops
            if game_state.turn_number <= 3 and self.useRightDoor and [3, 10] not in self.spawnBlacklist:
                while game_state.can_spawn(EMP, [3, 10]):
                    game_state.attempt_spawn(EMP, [3, 10])
            elif game_state.turn_number <= 3 and not self.useRightDoor and [24, 10] not in self.spawnBlacklist:
                while game_state.can_spawn(EMP, [24, 10]):
                    game_state.attempt_spawn(EMP, [24, 10])
            else:
                self.attackForMaxDestruction(game_state)    


        # reset the dictionary for the next analysis
        self.army_dict['total_count'] = 0
        self.army_dict['total_cost'] = 0
        self.army_dict['ping_count'] = 0
        self.army_dict['EMP_count'] = 0
        self.army_dict['scrambler_count'] = 0
        self.enemy_spawns.clear()
        self.my_EMP_ids.clear()
        game_state.submit_turn()
Esempio n. 14
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        p1UnitCount = len(self.jsonState.get('p1Units')[0]) + len(
            self.jsonState.get('p1Units')[1]) + len(
                self.jsonState.get('p1Units')[2])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(
            self.jsonState.get('p2Units')[1]) + len(
                self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))
        gamelib.debug_write('p2 army cost last turn = {}'.format(
            self.enemy_army_cost))

        if self.army_dict.get('total_cost', 0) > 0:
            self.lastEnemyArmyDict = self.army_dict.copy()

        if 'total_cost' in self.lastEnemyArmyDict and game_state.get_resource(
                game_state.BITS, 1) >= self.lastEnemyArmyDict['total_cost']:
            gamelib.debug_write(
                'I predict that p2 will spawn an army this turn!')

        shouldRebuild = game_state.turn_number > 3
        shouldRebuildWall = p1UnitCount >= 27  #only reinforce if the full wall is in place
        needsStrongerCorners = game_state.turn_number > 3
        towersToBuild = 1
        self.coresToSpendOnRebuilding = 4

        if game_state.turn_number == 0:
            self.buildFirewalls(game_state,
                                [[1, 13], [3, 13], [24, 13], [26, 13]], FILTER,
                                False)
            self.buildFirewalls(game_state,
                                [[2, 13], [6, 11], [21, 11], [25, 13]],
                                DESTRUCTOR, False)
            game_state.attempt_spawn(SCRAMBLER, [22, 8])
            game_state.attempt_spawn(SCRAMBLER, [5, 8])
        elif game_state.turn_number == 1:
            if game_state.get_enemy_destructor_count_for_locations(
                [[0, 14], [1, 14], [2, 14], [3, 14], [4, 14], [5, 14]]) > 0:
                self.buildFirewalls(game_state, [[3, 11], [5, 11]], FILTER,
                                    False)
                self.buildFirewalls(game_state, [[4, 11]], ENCRYPTOR, False)
                self.possibleLeftSpawnCoords = [[3, 10]]
            elif game_state.get_enemy_destructor_count_for_locations(
                [[1, 15], [2, 15], [3, 15], [4, 15], [5, 15]]) > 0:
                self.buildFirewalls(game_state, [[3, 12], [5, 12]], FILTER,
                                    False)
                self.buildFirewalls(game_state, [[4, 12]], ENCRYPTOR, False)
                self.possibleLeftSpawnCoords = [[2, 11]]
            else:
                self.buildFirewalls(game_state, [[4, 13], [5, 13]], FILTER,
                                    False)
                self.buildFirewalls(game_state, [[4, 11]], ENCRYPTOR, False)
                self.possibleLeftSpawnCoords = [[1, 12]]

            if game_state.get_enemy_destructor_count_for_locations([[
                    22, 14
            ], [23, 14], [24, 14], [25, 14], [26, 14], [27, 14]]) > 0:
                self.buildFirewalls(game_state, [[22, 11], [24, 11]], FILTER,
                                    False)
                self.buildFirewalls(game_state, [[23, 11]], ENCRYPTOR, False)
                self.possibleRightSpawnCoords = [[24, 10]]
            elif game_state.get_enemy_destructor_count_for_locations(
                [[22, 15], [23, 15], [24, 15], [25, 15], [26, 15]]) > 0:
                self.buildFirewalls(game_state, [[22, 12], [24, 12]], FILTER,
                                    False)
                self.buildFirewalls(game_state, [[23, 12]], ENCRYPTOR, False)
                self.possibleRightSpawnCoords = [[25, 11]]
            else:
                self.buildFirewalls(game_state, [[22, 13], [23, 13]], FILTER,
                                    False)
                self.buildFirewalls(game_state, [[23, 11]], ENCRYPTOR, False)
                self.possibleRightSpawnCoords = [[26, 12]]

            game_state.attempt_spawn(EMP, self.possibleLeftSpawnCoords[0])
            game_state.attempt_spawn(EMP, self.possibleRightSpawnCoords[0])
        else:
            game_state.attempt_spawn(EMP, self.possibleLeftSpawnCoords[0])
            game_state.attempt_spawn(EMP, self.possibleRightSpawnCoords[0])

            # EMPs will be neutralized by my own encrypted EMPs.  Check if I need more encryptors
            if len(self.enemy_EMP_spawn_coords) > 0:
                leftEMPSpawnCoords = []
                rightEMPSpawnCoords = []
                for c in self.enemy_EMP_spawn_coords:
                    x, y = c
                    if x < 14:
                        leftEMPSpawnCoords.append(c)
                    else:
                        rightEMPSpawnCoords.append(c)
                leftEncryptorStrength = 0
                rightEncryptorStrenth = 0
                for c in self.jsonState.get('p2Units')[1]:
                    x = c[0]
                    if x < 14:
                        leftEncryptorStrength += 1
                    else:
                        rightEncryptorStrenth += 1
                enemyEMPsAffordable = game_state.get_resource(
                    game_state.BITS, 1) // 3

                # we want to build EMP army size + encryptor strength in encryptors
                if len(leftEMPSpawnCoords) > 0:
                    if game_state.count_units_in_locations(
                            self.leftEncryptorCoords
                    ) < enemyEMPsAffordable + leftEncryptorStrength:
                        self.buildFirewalls(game_state,
                                            self.leftEncryptorCoords,
                                            ENCRYPTOR, False, 1)
                if len(rightEMPSpawnCoords) > 0:
                    if game_state.count_units_in_locations(
                            self.rightEncryptorCoords
                    ) < enemyEMPsAffordable + rightEncryptorStrenth:
                        self.buildFirewalls(game_state,
                                            self.rightEncryptorCoords,
                                            ENCRYPTOR, False, 1)

            # towers will be the way to neutralize pings
            if len(self.enemy_ping_spawn_coords) > 0:
                self.buildFirewalls(game_state, self.middleTowerCoords,
                                    DESTRUCTOR, False)

            # towers will be the way to neutralize scramblers
            if len(self.enemy_scrambler_spawn_cords) > 0:
                self.buildFirewalls(game_state, self.middleTowerCoords,
                                    DESTRUCTOR, False)

        # reset the dictionary for the next analysis
        self.army_dict['total_count'] = 0
        self.army_dict['total_cost'] = 0
        self.army_dict['ping_count'] = 0
        self.army_dict['EMP_count'] = 0
        self.army_dict['scrambler_count'] = 0
        self.enemy_spawns.clear()
        self.my_EMP_ids.clear()
        game_state.submit_turn()
Esempio n. 15
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        #p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(self.jsonState.get('p2Units')[1]) + len(self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))
        
        # let's build the corners #
        if game_state.can_spawn(DESTRUCTOR, [0,13]):
            game_state.attempt_spawn(DESTRUCTOR, [0, 13])
        if game_state.can_spawn(DESTRUCTOR, [27, 13]):
            game_state.attempt_spawn(DESTRUCTOR, [27, 13])
        self.reinforceBreachLocation(game_state)

        # line detection #
        # only worry about mirror if we have good defense set up?
        firstRowDefenderCount = game_state.get_enemy_unit_count_for_row(game_state.game_map.FIRST_ENEMY_ROW)
        firstRowDestructorCount = game_state.get_enemy_destructor_count_for_row(game_state.game_map.FIRST_ENEMY_ROW)

        secondRowDefenderCount = game_state.get_enemy_unit_count_for_row(game_state.game_map.SECOND_ENEMY_ROW)
        secondRowDestructorCount = game_state.get_enemy_destructor_count_for_row(game_state.game_map.SECOND_ENEMY_ROW)
        
        thirdRowDefenderCount = game_state.get_enemy_unit_count_for_row(game_state.game_map.THIRD_ENEMY_ROW)
        thirdRowDestructorCount = game_state.get_enemy_destructor_count_for_row(game_state.game_map.THIRD_ENEMY_ROW)

        fourthRowDefenderCount = game_state.get_enemy_unit_count_for_row(game_state.game_map.FOURTH_ENEMY_ROW)
        fourthRowDestructorCount = game_state.get_enemy_destructor_count_for_row(game_state.game_map.FOURTH_ENEMY_ROW)
        
        gamelib.debug_write('row counts: {},{},{},{}'.format(firstRowDefenderCount, secondRowDefenderCount, thirdRowDefenderCount, fourthRowDefenderCount))

        # we may need to move our wall at some point
        if firstRowDestructorCount > 6:
            self.buildCastleWall = True
            self.castleWallRow = 10
        elif secondRowDestructorCount > 6:
            self.buildCastleWall = True
            self.castleWallRow = 11
        elif thirdRowDestructorCount > 6:
            self.buildCastleWall = True
            self.castleWallRow = 12
        elif fourthRowDefenderCount > 6:
            self.buildCastleWall = True
            self.castleWallRow = 13
        
        # this is problematic when it keeps dying
        if self.buildCastleWall:
            self.buildWall(game_state)

        if game_state.turn_number != 0:
            if game_state.turn_number > 70:
                # what about sending scramblers?
                if game_state.my_health < 5 and game_state.number_affordable(PING) > 20:
                    self.attackForMaxPain(game_state)
                elif game_state.project_future_bits() < game_state.get_resource(game_state.BITS) + 1:
                    self.attackForMaxPain(game_state)
            elif p2UnitCount < 8:
                self.attackForMaxPain(game_state)
            elif game_state.turn_number != 1 and game_state.turn_number % 28 in [0, 1, 2]:  
                if game_state.turn_number % 28 == 1:
                    for x in range(4):
                        game_state.attempt_remove([20, 13 - x])
                elif game_state.turn_number % 28 == 2:
                    self.attackForMaxTargets(game_state)
            else:
                self.attackForMaxDestruction(game_state)

        for location in self.reversedCoords:
            game_state.attempt_remove(location)

        game_state.submit_turn()
Esempio n. 16
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        p1UnitCount = len(self.jsonState.get('p1Units')[0]) + len(
            self.jsonState.get('p1Units')[1]) + len(
                self.jsonState.get('p1Units')[2])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(
            self.jsonState.get('p2Units')[1]) + len(
                self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))
        gamelib.debug_write('p2 army cost last turn = {}'.format(
            self.enemy_army_cost))

        self.totalCoresSpent = 0
        self.reservedCoordsForThisTurn = []

        for coord in self.reservedCoords:
            self.reservedCoordsForThisTurn.append(coord)

        if game_state.can_spawn(FILTER, [25, 13]):
            game_state.attempt_spawn(FILTER, [25, 13])

        path = game_state.find_path_to_edge([13, 0],
                                            game_state.game_map.TOP_RIGHT)
        reinforcementCoords = game_state.game_map.get_locations_in_range(
            [23, 11], 3)
        if not any((True for c in reinforcementCoords if c in path)):
            gamelib.debug_write('we are outside the path!')
            self.buildFirewalls(game_state, self.nineWall, FILTER, False)

        cornerCoords = [[0, 13], [1, 12], [2, 11]]
        if game_state.my_health <= 15 and any(
            (True for c in cornerCoords if c in self.breach_list)):
            self.buildFirewalls(game_state, self.rightCornerTowers, DESTRUCTOR,
                                False, 1)
            self.buildFirewalls(game_state, self.rightCornerFilters, FILTER,
                                False, 1)

        self.buildFirewalls(game_state, self.rightAssaultTowerCoords,
                            DESTRUCTOR, False, 1)
        self.buildFirewalls(game_state, self.rightAssaultTowerFilterCoords,
                            FILTER, False, 2)
        self.buildFirewalls(game_state, self.rightAssaultEncryptorCoords,
                            ENCRYPTOR, False, 1)
        self.reinforceLocationsEvenly(game_state, self.enemy_spawn_coords)

        shouldAttack = True
        path = game_state.find_path_to_edge([13, 0],
                                            game_state.game_map.TOP_RIGHT)
        if not any((True for c in reinforcementCoords if c in path)):
            gamelib.debug_write('we are outside the path!')
            shouldAttack = False

        gamelib.debug_write('{} - attack path={}'.format(
            game_state.turn_number, len(path)))
        if len(path) > 30:
            shouldAttack = False

        defendingDestructors = len(game_state.get_attackers([26, 13], 0))
        defendingFilters = game_state.get_enemy_filter_count_for_locations(
            [[26, 14], [27, 14]])
        if game_state.number_affordable(
                PING) < defendingDestructors + defendingFilters + 1:
            shouldAttack = False

        if shouldAttack:
            x, y = path[-1]
            gamelib.debug_write('Final step: {}'.format(path[-1]))
            if [26, 13] in path and game_state.turn_number > 0:
                if self.attackedWithScramblers and self.lastEnemyHealth >= game_state.enemy_health - 4:
                    if game_state.number_affordable(
                            EMP) >= 3 + 1 * game_state.turn_number // 12:
                        game_state.attempt_spawn(
                            EMP, [13, 0], game_state.number_affordable(EMP))
                        self.attackedWithScramblers = False
                        self.attackedLastTurn = True
                        shouldAttack = False
                    else:
                        shouldAttack = False
                elif y == 13 or self.attackedLastTurn and self.lastEnemyHealth >= game_state.enemy_health - 4:
                    game_state.attempt_spawn(
                        SCRAMBLER, [24, 10],
                        defendingDestructors + defendingFilters + 1)
                    self.attackedWithScramblers = True
                    self.attackedLastTurn = True

            if shouldAttack and game_state.number_affordable(PING) > 2:
                game_state.attempt_spawn(PING, [13, 0],
                                         game_state.number_affordable(PING))
                self.attackedLastTurn = True
        else:
            self.attackedLastTurn = False

        self.lastEnemyHealth = game_state.enemy_health
        game_state.submit_turn()
Esempio n. 17
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        #p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(
            self.jsonState.get('p2Units')[1]) + len(
                self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))

        self.reinforceBreachLocation(game_state)

        # line detection #
        # only worry about mirror if we have good defense set up?
        firstRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.FIRST_ENEMY_ROW)
        firstRowDestructorCount = game_state.get_enemy_destructor_count_for_row(
            game_state.game_map.FIRST_ENEMY_ROW)

        secondRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.SECOND_ENEMY_ROW)
        secondRowDestructorCount = game_state.get_enemy_destructor_count_for_row(
            game_state.game_map.SECOND_ENEMY_ROW)

        thirdRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.THIRD_ENEMY_ROW)
        thirdRowDestructorCount = game_state.get_enemy_destructor_count_for_row(
            game_state.game_map.THIRD_ENEMY_ROW)

        fourthRowDefenderCount = game_state.get_enemy_unit_count_for_row(
            game_state.game_map.FOURTH_ENEMY_ROW)
        fourthRowDestructorCount = game_state.get_enemy_destructor_count_for_row(
            game_state.game_map.FOURTH_ENEMY_ROW)

        gamelib.debug_write('row counts: {},{},{},{}'.format(
            firstRowDefenderCount, secondRowDefenderCount,
            thirdRowDefenderCount, fourthRowDefenderCount))

        # we may need to advance our wall

        # a common pattern is a row of filters infront of a row of destructors, we want to focus on the destructors!
        if secondRowDestructorCount > 4:
            self.mirrorEnemy(game_state, game_state.game_map.SECOND_ENEMY_ROW)
        elif thirdRowDestructorCount > 4:
            self.mirrorEnemy(game_state, game_state.game_map.THIRD_ENEMY_ROW)
        elif fourthRowDestructorCount > 4:
            self.mirrorEnemy(game_state, game_state.game_map.FOURTH_ENEMY_ROW)
        elif firstRowDefenderCount > 8:
            self.mirrorEnemy(game_state, game_state.game_map.FIRST_ENEMY_ROW)
        elif secondRowDefenderCount > 6:
            self.mirrorEnemy(game_state, game_state.game_map.SECOND_ENEMY_ROW)
        elif thirdRowDefenderCount > 6:
            self.mirrorEnemy(game_state, game_state.game_map.THIRD_ENEMY_ROW)
        elif fourthRowDefenderCount > 6:
            self.mirrorEnemy(game_state, game_state.game_map.FOURTH_ENEMY_ROW)

        # make sure we haven't blocked ourselves in
        for x in range(4):
            openSpots = game_state.row_openings(13 - x)
            if openSpots == 0:
                # open it back up!
                game_state.attempt_remove([20, 13 - x])

        if game_state.turn_number != 0:
            if p2UnitCount < 8:
                self.attackForMaxPain(game_state)
            else:
                self.attackForMaxDestruction(game_state)

        game_state.submit_turn()
Esempio n. 18
0
    def on_turn(self, turn_state):
        game_state = gamelib.AdvancedGameState(self.config, turn_state)
        #p1UnitCount = len(self.jsonState.get('p1Units')[0])
        p2UnitCount = len(self.jsonState.get('p2Units')[0]) + len(
            self.jsonState.get('p2Units')[1]) + len(
                self.jsonState.get('p2Units')[2])
        gamelib.debug_write('p2 has {} units'.format(p2UnitCount))

        self.totalCoresSpent = 0
        self.reservedCoordsForThisTurn = []
        for coord in self.reservedCoords:
            self.reservedCoordsForThisTurn.append(coord)

        self.buildTurnZeroTowers(game_state)

        # consider front line being FILTERS? Does it matter if they use EMPs? YES!! PINGS need these to be towers
        # NEED TO COUNTER HEAVY EMP DESTRUCTION, we can't afford to build enough defense when EMPs wreck havok
        if self.enemy_EMP_spawn_count > self.enemy_ping_spawn_count:
            gamelib.debug_write('p2 likes to spawn EMPs. {} > {}'.format(
                self.enemy_EMP_spawn_count, self.enemy_ping_spawn_count))
            for x in range(28):
                if [x, 13] not in self.betterAsFilter:
                    self.betterAsFilter.append([x, 13])
        else:
            gamelib.debug_write('p2 likes to spawn Pings. {} < {}'.format(
                self.enemy_EMP_spawn_count, self.enemy_ping_spawn_count))
            self.betterAsFilter = []

        if not self.doesEnemyHorde and game_state.turn_number > 4 and game_state.get_resource(
                game_state.CORES, 1) >= 10:
            gamelib.debug_write('p2 is a HORDER! CORES:{}'.format(
                game_state.get_resource(game_state.CORES, 1)))
            # once a horder, always a horder
            self.doesEnemyHorde = True
            self.attackForPain = True

        if self.attackedLastTurn:
            if self.attackForPain and game_state.enemy_health == self.lastEnemyHealth:
                gamelib.debug_write(
                    'Tried to hurt them and failed! Changing strategies.')
                if not self.doesEnemyHorde:
                    self.attackForPain = False
            elif p2UnitCount >= self.lastEnemyUnitCount + 4:
                # TODO # This is not good enough, we lose some games where switching to PINGS might have made the difference
                gamelib.debug_write(
                    'Tried to damage them and failed! Changing strategies.')
                self.attackForPain = True

        self.attackedLastTurn = False

        # we need to be careful overbuilding on any one turn, so pretend we never have more than 26 cores #
        # TODO # DONE

        if game_state.turn_number == 0:
            self.spawnScramblerJammers(game_state)
        else:
            # if we haven't seen an enemy spawn yet (and it's still early)
            if game_state.turn_number < 3 and len(
                    self.enemy_spawn_coords) == 0:
                self.spawnScramblerJammers(game_state)

            self.markForRefund(game_state)
            # NEED TO CONSIDER ALGOs THAT HORDE CORES AND WHAT HAPPENS AFTER MASSIVE DESTRUCTION
            # more complex comparisson would be if they can afford to replace all that was destroyed ...
            if self.lastEnemyUnitCount > p2UnitCount and game_state.get_resource(
                    game_state.CORES, 1) > 6:
                coordsToReinforce = self.reinforceLocationsEvenly(
                    self.lastTurnGameState, self.enemy_spawn_coords)
                for location in coordsToReinforce:
                    attackers = len(game_state.get_attackers(location, 1))
                    if attackers < 5:
                        self.reinforceLocation(game_state, location,
                                               5 - attackers)
            else:
                self.reinforceLocationsEvenly(game_state,
                                              self.enemy_spawn_coords)

            if self.attackForPain:
                if game_state.number_affordable(
                        PING) >= 12 + game_state.turn_number // 5:
                    self.attackForMaxPain(game_state)
                    self.attackedLastTurn = True
                else:
                    self.attackedLastTurn = False
            else:
                if game_state.number_affordable(
                        EMP) >= 3 + game_state.turn_number // 15:
                    self.attackForMaxDestruction(game_state)
                    self.attackedLastTurn = True
                else:
                    self.attackedLastTurn = False

        gamelib.debug_write('SUMBITTING TURN {}'.format(
            game_state.turn_number))
        self.lastEnemyHealth = game_state.enemy_health
        self.lastEnemyUnitCount = p2UnitCount
        self.lastTurnGameState = game_state
        game_state.submit_turn()