Problems scanning for enemy shipyards (python)


Hello, everybody.

I am using the following python code snippet in an attempt to scan for enemy shipyards; at some point it’ll be used for other cell-by-cell preprocessing before the turn-based portion of the code commences, as well. This code is called after game = hlt.Game() and game.ready("nightMiner"), but before anything else:

def scan_for_enemy_shipyards(game):
    # identify map data for Const storage and later retrieval
    glo.Misc.loggit('preprocessing', 'info', "Scanning for enemy shipyards")

    for x in range(0, game.game_map.width):
        glo.Misc.loggit('preprocessing', 'debug', " - scanning column: " + str(x))
        for y in range(0, game.game_map.height):
            # check each map cell
            glo.Misc.loggit('preprocessing', 'debug', "  - scanning cell: " + str(Position(x, y)))
            if game.game_map[Position(x, y)].has_structure:
                glo.Misc.loggit('preprocessing', 'debug', "  -* _HAS_ structure")

            # NOTE: this only verifies that it's not our shipyard, as no drops would exist yet
            if game.game_map[Position(x, y)].structure_type is not None and \
           != Position(x, y):
                # there is a structure that is not ours
                glo.Misc.loggit('preprocessing', 'debug', "Enemy shipyard at: " + str(Position(x, y)))

                glo.Const.Enemy_Drops.append(Position(x, y))


Unfortunately, I’m not even able to find any information regarding a structure on any of the positions in the entire map. I was wondering if this may be due to the fact that the game_map has not been set up at this point, and if so, what point I will need to tuck it after, or if it’s something else, maybe not being able to use a newly created Position() reference to index the game_map, or something of the sort…

Also, I think that I scanned all of the relevant areas in the hlt.* library, but if there is some easier way to obtain a list of the shipyards, I’d really be interested in hearing about it.

Thanks in advance & happy coding!


May I ask you a question? Why you iterate over map cells while you can iterate over players structures directly?

for player in game.players:
    if player is not


I was totally not aware of that capability. That very much simplifies the problem that I was making too difficult… Thank you for pointing that out!


You should take a look at API docs. I wonder why people start to write something before reading basic tutorial or source code.


I have been, but thank you for pointing out that I didn’t see that point clearly and insinuating that it’s my deliberate ignorance instead of misunderstanding and/or a documentation issue.


Hah. My bad, I was absolutly sure that docs mentions game.players. When I started do develop my bot I just look throght autocompele in PyCharm and some source code when I need access something. Game object definetly has player attribute
I think I will open issue on github beacuse it’s a second thread about accessing enemy ships/dropoffs.


Also I forget it is a dict not a list. So you need game.players.values()