oxwhirl/smac

Is it possible to get the type of each agent?

GoingMyWay opened this issue · 8 comments

Is it possible to get the type of each agent? For example

# load 3m
for id, agent in env.agents.items():
    print(agent.agent_type)   # should be marine

AFAIK, there is no easy way to know what is the specific SC2 type of a unit. The closest I got and what I ended up using in my experiments was agent.unit_type to tell them apart. However, agents and enemies of the same SC2 type will have different unit_types, so be careful.

Maybe we could find a way for SMAC to provide SC2 types? I imagine some people would find it useful for specific tasks, e.g. transfer learning among maps.

Another thing I just remembered (and I don't know if this interests you) is that, even if an agent and an enemy have the same SC2 type (e.g. Marine), agents act very differently than normal SC2 units in that agent movement is more constrained (up down left right) and they have to retain actions for a certain number of game steps, whereas enemy units are totally controlled by the game and act more like what you'd expect from an SC2 gameplay standpoint.

@douglasrizzo

I tried from pysc2.lib.units import get_unit_type, it can get the type of enemies, however, it cannot return the correct type of MARL agents.

IIRC @samvelyan mentioned that the agent units have been redefined or created inside the map file, in order to implement the different behavior they have. So maybe pysc2 can't recognize them?

Yes, we have specific "RL units" which I created manually (basically copied from their original and changed a few properties). Check this document for Unit Creation details. I think pysc2 might not be able to recognise them.

In SMAC we manually keep track of unit ids though. Check out _init_ally_unit_types() here. One could just write a dictionary/function that returns appropriate strings given these unit ids. Happy to accept the PR if this is something you want to add. :)

Yes, we have specific "RL units" which I created manually (basically copied from their original and changed a few properties). Check this document for Unit Creation details. I think pysc2 might not be able to recognise them.

In SMAC we manually keep track of unit ids though. Check out _init_ally_unit_types() here. One could just write a dictionary/function that returns appropriate strings given these unit ids. Happy to accept the PR if this is something you want to add. :)

Hello, thanks for your excellent work.

I have created an empty map and design several new RL units but not create the units in the map, and I want to create the RL unit after loading the empty map in the smac as follow:

cmd = d_pb.DebugCommand(
                    create_unit=d_pb.DebugCreateUnit(
                        unit_type=unit_type,
                        owner=owner,
                        pos=pos,
                        quantity=quantity))
self._controller.debug(cmd)

How can I get the unit_type of the uncreated RL unit?

Hope to receive your reply. Thank you!

Hi @liushunyu ,

Each version of SC2 has a fixed set of existing units (e.g. let's assume the last unit has the id x). Then when you create a new unit using the SC2 Editor (you'd need to do this manually in advance), that unit receives the a new id equal to x+1. If you create 10 new units, they will receive ids from x+1 to x+10 sorted alphabetically using unit name.

For build version 75689 (4.10.0), x = 1969. For build version 82893 (5.0.5), x = 2004. For other versions, you'd need to create a new unit using SC2 Editor, print its unit_type and identify the exact number.

Hope this helps!

Feel free to reopen the issue if there are further questions.

Thank you!!! @samvelyan