How do i get all units on the board?

If i iterate over de game_map i only get the units info in strings. How can i get all the units on the bord?

Well, i keep on posting questions on this forum but i keep on figuring it out in just a few mins later. I made this function with as input the turn_state:

def get_all_units(self,line):
    state= json.loads(line)
    typedef= self.config.get("unitInformation")
    p1units=state['p1Units']
    p2units=state['p2Units']
    p1unit_info=[]
    p2unit_info=[]
    for i, unit_types in enumerate(p1units):
        for uinfo in unit_types:
            unit_type = typedef[i].get("shorthand")
            sx, sy, shp = uinfo[:3]
            x, y = map(int, [sx, sy])
            hp = float(shp)
            p1unit_info.append([unit_type, x, y, 0])
    for i, unit_types in enumerate(p2units):
        for uinfo in unit_types:
            unit_type = typedef[i].get("shorthand")
            sx, sy, shp = uinfo[:3]
            x, y = map(int, [sx, sy])
            hp = float(shp)
            p2unit_info.append([unit_type, x, y, 1])
    return p1unit_info+p2unit_info

This returns a array with information about all the units in this format: [unit typ, unit x, unit y, if this is a 0 then player 1 if this is a 1 then its player 2]. hopefully i helped some1 else bcs i just spent a whole f***** evening figuring this out xD T-T

4 Likes

This works well, as an alternative solution you could also store the units when the engine first runs in the __create_parsed_units function. Rather than parsing the string again, simply create a list for friendly units and enemy units in ‘game_state.py’ and then add to the list when the engine creates a parsed unit. This means you don’t have to parse the information twice.

3 Likes

Well its great you answer your own questions here because maybe it will help people with similar issues later!