Can't figure out get_attackers

Really didn’t want to make this post as I know I’m missing something blatantly obvious, but I can’t for the life of me figure out how get_attackers works. If the enemy has a destructor on [24, 15] and I call get_attackers([26, 16], 0), shouldn’t it return that a destructor can attack that tile? Or is this not how you use it.

The way I interpret the docs, calling get_attackers([26, 16], 1) is the proper way to check if an enemy destructor can attack [26,16], but the example method provided uses “0” for player index. Either way, I don’t get the correct result.

Thanks in advance!

I agree that the docs are a bit confusing. I’m using a player index of 1 to get my destructors that can attack an opponent unit and an index of 0 to get opponent destructors that can attack my unit.

If an enemy destructor is placed at [26, 15], then would the following find and return the destructor?

game_state.get_attackers([23, 15], 0)
game_state.get_attackers([24, 15], 0)
game_state.get_attackers([26, 12], 0)
game_state.get_attackers([26, 15], 0)
game_state.get_attackers([27, 14], 0)

When I do something along the lines of this, it might return the destructor for maybe 1 or 2 of these 5 calls, and it seems to be completely random. How should I be doing it?

The way I see it, get_attackers returns a list of destructors that are attacking a given point.

You could try calling the function and looping through the list.

For example:

units = game_state.get_attackers(point,0)
for unit in units:
    #do stuff with unit

You could probably also do something like this but this is exactly what get_attackers does anyway.

possibleunits= self.game_map.get_locations_in_range(point, 3.5)
for pos in possibleunits:
    unit = game_state.contains_stationary_unit(pos)
    if unit:
        #do stuff w unit again

If, for some reason, you wanted to find a unit at just [26,15] you could use

unit = game_state.contains_stationary_unit([26,15])
if unit:
   #something to do with unit

Or multiple, like

points = [[23,15],[24,15],[26,12],[26,15],[27,14]]
for pos in points:
    unit = game_state.contains_stationary_unit(pos)
    if unit:
        #do stuff w units

Also, how did you test the code written in your last post?


Thank you very much! I think I was improperly using the units that were returned. This helped a lot.