Find unit type at given location

Find unit type at given location
0

#1

How do I find if there are and what unit there are at a given location?


#2

You can get list of units at speecific location using game map:

units = game_state.game_map[location]

Then you can iterate through that list and get units type:

for unit in units:
   unit.unit_type

#3

tack


#4

Actually if you are checking for a stationary unit, there is a bit better method:

game_state.contains_stationary_unit(location)

It returns GameUnit or False and you can address it directly without iterating.


#5

I don’t think this is needed, but I added this to game_state

def contains_unit_of_type(self, type, location):
    x, y = map(int, location)
    if self.game_map[x,y] == None:
        return False
    for unit in self.game_map[x,y]:
        if unit.unit_type == type:
            return unit
        return False

Then I was doing this to calculate destructor threat range

def enemy_des_threat(self, game_state):
    top_occupied = self.enemy_occupied(game_state)
    enemy_des = []
    for pos in top_occupied:
        if game_state.contains_unit_of_type(DESTRUCTOR, pos) != False:
            enemy_des.append(pos)
    enemy_des_range = []
    for pos in enemy_des:
        des_range = ((game_state.game_map.get_locations_in_range(pos, 3)))
        for pos in des_range:
            if game_state.game_map.in_arena_bounds(pos):
                enemy_des_range.append(pos)
    return enemy_des_range

I’m pretty sure I found this in an older thread and added it to my code. It can be useful, like if a path goes through a certain number of destructor damage range, you could drop the path. Or if you want to say wait until we have x pings before taking this path. It can be tricky to implement, effectively though, I’ve used it, but sometimes it doesn’t seem like it’s worth the effort.


#6

@Toastyone you are on the right path my firend.

First, I would suggest to not edit files from the starter algo directly, try to extend them (and at some point replace them) one by one.
“Core” files have realy good validations, and well unit tested to obay the game logic. Making changes there and possible introducing bugs and will bring you a lot of pain.

After you create a good set of similar scanning functions the next step is to try to build a full turn simulator :slight_smile:


#7

The furthest I got last Season, basically, I found out the spawn points of enemy information units from the previous turn, going back 3 turns i think, then trying to run a rudimentary hypothetical spawn point, and deployed defenses based on their paths, funny enough those algos did worse than two basic algo’s I made, a ping gun, and then one that just does a line of filters and destructors on 11, and a bunch of random destructors above that.

I haven’t put a lot of work in yet this season, but out of the one’s I have running it’s still doing the best, which means I’m guessing there was some error in the logic I was using in the other ones, since I did notice it didn’t always seem to spawn defenses on the correct side, so hopefully I can work those out this season and actually make it in the top 10.
https://terminal.c1games.com/watch/3941966