From ae1759578f20f28020e108fef5563bc121eff3c1 Mon Sep 17 00:00:00 2001 From: Matteo Bettini <55539777+matteobettini@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:30:15 +0100 Subject: [PATCH] [Task] VMAS football (#166) * football * football * fix * amend --- benchmarl/conf/task/vmas/football.yaml | 66 +++++++++++++++++++++++++ benchmarl/environments/vmas/common.py | 1 + benchmarl/environments/vmas/football.py | 66 +++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 benchmarl/conf/task/vmas/football.yaml create mode 100644 benchmarl/environments/vmas/football.py diff --git a/benchmarl/conf/task/vmas/football.yaml b/benchmarl/conf/task/vmas/football.yaml new file mode 100644 index 00000000..bf65762b --- /dev/null +++ b/benchmarl/conf/task/vmas/football.yaml @@ -0,0 +1,66 @@ +defaults: + - vmas_football_config + - _self_ + + +max_steps: 500 + +# Agents config +n_blue_agents: 3 +n_red_agents: 3 +ai_red_agents: True # What agents should be learning and what controlled by the heuristic (ai) + +# When you have 5 blue agents, physical differences can be introduced: +# 1 goalkeeper -> slow and big +# 2 defenders -> normal size and speed (agent_size, u_multiplier, max_speed) +# 2 attackers -> small and fast +physically_different: False + +# Agent spawning +spawn_in_formation: False +only_blue_formation: True # Only spawn blue agents in formation +formation_agents_per_column: 2 +randomise_formation_indices: False # If False, each agent will always be in the same formation spot +formation_noise: 0.2 # Noise on formation positions + +# Ai config +n_traj_points: 0 # Number of spline trajectory points to plot for heuristic (ai) agents +ai_strength: 1.0 # The speed of the ai 0<=x<=1 +ai_decision_strength: 1.0 # The decision strength of the ai 0<=x<=1 +ai_precision_strength: 1.0 # The precision strength of the ai 0<=x<=1 + +# Task sizes +agent_size: 0.025 +goal_size: 0.35 +goal_depth: 0.1 +pitch_length: 3.0 +pitch_width: 1.5 +ball_mass: 0.25 +ball_size: 0.02 + +# Actions +u_multiplier: 0.1 + +# Actions shooting +enable_shooting: False # Whether to enable an extra 2 actions (for rotation and shooting). Only available for non-ai agents +u_rot_multiplier: 0.0003 +u_shoot_multiplier: 0.6 +shooting_radius: 0.08 +shooting_angle: 1.5708 + +# Speeds +max_speed: 0.15 +ball_max_speed: 0.3 + +# Rewards +dense_reward: True +pos_shaping_factor_ball_goal: 10.0 # Reward for moving the ball towards the opponents' goal. This can be annealed in a curriculum. +pos_shaping_factor_agent_ball: 0.1 # Reward for moving the closest agent to the ball in a team closer to it. +# This reward does not trigger if the agent is less than distance_to_ball_trigger from the ball or the ball is moving +distance_to_ball_trigger: 0.4 +scoring_reward: 100.0 # Discrete reward for scoring + +# Observations +observe_teammates: True +observe_adversaries: True +dict_obs: False diff --git a/benchmarl/environments/vmas/common.py b/benchmarl/environments/vmas/common.py index dd77a249..ac6c2816 100644 --- a/benchmarl/environments/vmas/common.py +++ b/benchmarl/environments/vmas/common.py @@ -36,6 +36,7 @@ class VmasTask(Task): BUZZ_WIRE = None FLOCKING = None DISCOVERY = None + FOOTBALL = None SIMPLE_ADVERSARY = None SIMPLE_CRYPTO = None SIMPLE_PUSH = None diff --git a/benchmarl/environments/vmas/football.py b/benchmarl/environments/vmas/football.py new file mode 100644 index 00000000..aa17ad96 --- /dev/null +++ b/benchmarl/environments/vmas/football.py @@ -0,0 +1,66 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING + + # Agents config + n_blue_agents: int = MISSING + n_red_agents: int = MISSING + ai_red_agents: bool = MISSING + physically_different: bool = MISSING + + # Agent spawning + spawn_in_formation: bool = MISSING + formation_agents_per_column: int = MISSING + randomise_formation_indices: bool = MISSING + only_blue_formation: bool = MISSING + formation_noise: float = MISSING + + # Opponent heuristic config + n_traj_points: int = MISSING + ai_strength: float = MISSING + ai_decision_strength: float = MISSING + ai_precision_strength: float = MISSING + + # Task sizes + agent_size: float = MISSING + goal_size: float = MISSING + goal_depth: float = MISSING + pitch_length: float = MISSING + pitch_width: float = MISSING + ball_mass: float = MISSING + ball_size: float = MISSING + + # Actions + u_multiplier: float = MISSING + + # Actions shooting + enable_shooting: bool = MISSING + u_rot_multiplier: float = MISSING + u_shoot_multiplier: float = MISSING + shooting_radius: float = MISSING + shooting_angle: float = MISSING + + # Speeds + max_speed: float = MISSING + ball_max_speed: float = MISSING + + # Rewards + dense_reward: bool = MISSING + pos_shaping_factor_ball_goal: float = MISSING + pos_shaping_factor_agent_ball: float = MISSING + distance_to_ball_trigger: float = MISSING + scoring_reward: float = MISSING + + # Observations + observe_teammates: bool = MISSING + observe_adversaries: bool = MISSING + dict_obs: bool = MISSING