Config¶
- class magent2.gridworld.Config¶
Configuration class for a Gridworld game.
Methods¶
- magent2.gridworld.Config.set(self, args: dict)¶
Set parameters of global configuration.
- Parameters:
args (dict)
- Contains the following configuration attributes:
map_width (int): Number of horizontal grid squares in the Gridworld.
map_height (int): Number of vertical grid squares in the Gridworld.
embedding_size (int): Embedding size for the observation features.
render_dir (str): Directory to save render file.
seed (int): Random seed.
food_mode (bool): Dead agents drop food on the map.
turn_mode (bool): Include 2 more actions – turn left and turn right.
minimap_mode (bool): Include minimap in observations.
- magent2.gridworld.Config.register_agent_type(self, name: str, attr: dict)¶
Register an agent type.
- Parameters:
name (str) – Name of the type (should be unique).
attr (dict)
- Contains the following configuration attributes:
height (int): Height of agent body.
width (int): Width of agent body.
speed (float): Maximum speed, i.e. the radius of move circle of the agent.
hp (float): Maximum health point of the agent.
view_range (gw.CircleRange or gw.SectorRange): Field of view of the agent.
damage (float): Attack damage.
step_recover (float): Step recover (healing) of health points (can be negative).
kill_supply (float): Hp gain for killing this type of agent.
step_reward (float): Reward gained in every step.
kill_reward (float): Reward gained for killing this type of agent.
dead_penalty (float): Reward gained for dying.
attack_penalty (float): Reward gained when performing an attack (to discourage attacking empty grid cells).
- Returns:
name (str): Name of the type.
- magent2.gridworld.Config.add_group(self, agent_type: str)¶
Add a group to the configuration.
- Parameters:
agent_type (str) – Name of agent type contained in this group.
- Returns:
group_handle (int) – Handle for the new group.
- magent2.gridworld.Config.add_reward_rule(self, on: EventNode, receiver: List[AgentSymbol], value: List[float], terminal: bool = False)¶
Add a reward rule.
- Parameters:
on (Event) – An objecting representing a bool expression of the trigger event.
receiver (List[AgentSymbol]) – Receiver of this reward rule. If the receiver is not a deterministic agent, it must be one of the agents involved in the triggering event.
List[float] (value) – Value to assign.
terminal (bool) – Whether this event will terminate the game.
Helper classes¶
AgentSymbol and Event¶
AgentSymbol
and Event
are helper classes used to design rewards that go into the Config.
AgentSymbol
s are used to represent some set of agents. They are instantiated with a group handle and the relevant agents within that group. The index can be a single number or “any” or “all”.
Here is an example of creating two symbols, one for each of two groups:
import magent2.gridworld.AgentSymbol
as1 = AgentSymbol(group_1, index="any")
as2 = AgentSymbol(group_2, index="any")
Event
s establish what must occur to trigger a reward disbursement. They are called with a subject (AgentSymbol
), predicate, and relevant args.
Here are the available predicates and corresponding args:
Predicate |
Args |
---|---|
kill |
AgentSymbol |
at |
(x, y) |
in |
((x1, y1), (x2, y2)) |
attack |
AgentSymbol |
collide |
AgentSymbol |
die |
(empty) |
in_a_line |
(empty) |
align |
(empty) |
Here is an example creating reward rules for the two groups to attack each other:
from magent2.gridworld import Config, Event
config = Config()
e1 = Event(as1, "attack", as2)
config.add_reward_rule(e1, receiver=as1, value=attack_opponent_reward)
e2 = Event(as2, "attack", as1)
config.add_reward_rule(e2, receiver=as2, value=attack_opponent_reward)
More examples can be found in the reference environments.
View Range¶
When using register_agent_type()
, the attribute view_range
is defined using one of the following classes:
- class magent2.gridworld.CircleRange(radius)¶
- class magent2.gridworld.SectorRange(radius, angle)¶