Skip to content

Commit a60b26a

Browse files
committed
cp
1 parent ef5f7f2 commit a60b26a

25 files changed

+62
-63
lines changed

packages/cogames/TECHNICAL_MANUAL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Example command names:
173173
- `change_vibe_sad`
174174
- `change_vibe_neutral`
175175

176-
> **Note**: The number of available vibes is configurable via `change_vibe.number_of_vibes`.
176+
> **Note**: The available vibes are configurable via `change_vibe.vibes`.
177177
178178
---
179179

packages/cogames/scripts/run_evaluation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ def _ensure_vibe_supports_gear(env_cfg) -> None:
6666
break
6767
if uses_gear:
6868
change_vibe = env_cfg.game.actions.change_vibe
69-
if getattr(change_vibe, "number_of_vibes", 0) < 8:
70-
change_vibe.number_of_vibes = 8
69+
has_gear = any(v.name == "gear" for v in change_vibe.vibes)
70+
if not has_gear:
71+
from mettagrid.config.vibes import VIBE_BY_NAME
72+
73+
change_vibe.vibes = list(change_vibe.vibes) + [VIBE_BY_NAME["gear"]]
7174

7275

7376
# Cache for policy action space sizes to avoid reloading checkpoints
@@ -139,7 +142,7 @@ def _configure_env_for_action_space(env_cfg, num_actions: int) -> None:
139142
if env_cfg.game.actions:
140143
# Configure vibe action count
141144
if env_cfg.game.actions.change_vibe:
142-
env_cfg.game.actions.change_vibe.number_of_vibes = len(vibe_names)
145+
env_cfg.game.actions.change_vibe.vibes = [vibes_module.VIBE_BY_NAME[name] for name in vibe_names]
143146
# Filter initial vibe if out of range
144147
if env_cfg.game.agent.initial_vibe >= len(vibe_names):
145148
env_cfg.game.agent.initial_vibe = 0

packages/cogames/src/cogames/cogs_vs_clips/mission.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
ProtocolConfig,
3434
ResourceLimitsConfig,
3535
)
36+
from mettagrid.config.vibes import Vibe
3637
from mettagrid.map_builder.map_builder import AnyMapBuilderConfig
3738

3839

@@ -134,7 +135,7 @@ class Mission(Config):
134135
heart_capacity: int = Field(default=1)
135136
# Control vibe swapping in variants
136137
enable_vibe_change: bool = Field(default=True)
137-
vibe_count: int | None = Field(default=None)
138+
vibes: list[Vibe] | None = Field(default=None)
138139
compass_enabled: bool = Field(default=True)
139140

140141
def __init__(self, **kwargs):
@@ -173,10 +174,10 @@ def make_env(self) -> MettaGridConfig:
173174
move=MoveActionConfig(consumed_resources={"energy": self.move_energy_cost}),
174175
noop=NoopActionConfig(),
175176
change_vibe=ChangeVibeActionConfig(
176-
number_of_vibes=(
177-
0
177+
vibes=(
178+
[]
178179
if not self.enable_vibe_change
179-
else (self.vibe_count if self.vibe_count is not None else len(vibes.VIBES))
180+
else (self.vibes if self.vibes is not None else list(vibes.VIBES))
180181
)
181182
),
182183
),

packages/cogames/src/cogames/policy/nim_agents/thinky_eval.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ def _ensure_vibe_supports_gear(env_cfg) -> None:
144144
break
145145
if uses_gear:
146146
change_vibe = env_cfg.game.actions.change_vibe
147-
if getattr(change_vibe, "number_of_vibes", 0) < 8:
148-
change_vibe.number_of_vibes = 8
147+
has_gear = any(v.name == "gear" for v in change_vibe.vibes)
148+
if not has_gear:
149+
from mettagrid.config.vibes import VIBE_BY_NAME
150+
151+
change_vibe.vibes = list(change_vibe.vibes) + [VIBE_BY_NAME["gear"]]
149152
except Exception:
150153
pass
151154

packages/cogames/src/cogames/policy/scripted_agent/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def change_vibe_action(
291291
return actions.noop.Noop()
292292
if not getattr(change_vibe_cfg, "enabled", True):
293293
return actions.noop.Noop()
294-
num_vibes = int(getattr(change_vibe_cfg, "number_of_vibes", 0))
294+
num_vibes = len(getattr(change_vibe_cfg, "vibes", []))
295295
if num_vibes <= 1:
296296
return actions.noop.Noop()
297297
# Raise loudly if the requested vibe isn't registered instead of silently

packages/cogames/tests/test_cvc_assembler_hearts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def _make_simulation() -> Simulation:
4242
cfg.game.actions.noop.enabled = True
4343
cfg.game.actions.move.enabled = True
4444
cfg.game.actions.change_vibe.enabled = True
45-
cfg.game.actions.change_vibe.number_of_vibes = 32
4645

4746
assembler_cfg = CvCAssemblerConfig(
4847
first_heart_cost=FIRST_HEART_COST, additional_heart_cost=ADDITIONAL_HEART_COST

packages/mettagrid/docs/actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Example action names:
9797
- `change_vibe_sad`
9898
- `change_vibe_neutral`
9999

100-
> **Note**: The number of available vibes is configurable via `change_vibe.number_of_vibes`.
100+
> **Note**: The available vibes are configurable via `change_vibe.vibes`.
101101
102102
### Attack Actions
103103

packages/mettagrid/python/src/mettagrid/config/mettagrid_c_config.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
GameConfig,
77
WallConfig,
88
)
9-
from mettagrid.config.vibes import VIBES
109
from mettagrid.mettagrid_c import ActionConfig as CppActionConfig
1110
from mettagrid.mettagrid_c import AgentConfig as CppAgentConfig
1211
from mettagrid.mettagrid_c import AssemblerConfig as CppAssemblerConfig
@@ -36,15 +35,12 @@ def convert_to_cpp_game_config(mettagrid_config: dict | GameConfig):
3635
if "obs" in config_dict and "features" in config_dict["obs"]:
3736
config_dict["obs"] = config_dict["obs"].copy()
3837
config_dict["obs"].pop("features", None)
39-
# Keep vibe_names in sync with number_of_vibes; favor the explicit count.
38+
# Keep vibe_names in sync with vibes; favor the vibes list.
4039
config_dict.pop("vibe_names", None)
41-
change_vibe_cfg = config_dict.setdefault("actions", {}).setdefault("change_vibe", {})
42-
change_vibe_cfg["number_of_vibes"] = change_vibe_cfg.get("number_of_vibes") or len(VIBES)
4340
game_config = GameConfig(**config_dict)
4441

4542
# Ensure runtime object has consistent vibes.
46-
game_config.actions.change_vibe.number_of_vibes = game_config.actions.change_vibe.number_of_vibes or len(VIBES)
47-
game_config.vibe_names = [vibe.name for vibe in VIBES[: game_config.actions.change_vibe.number_of_vibes]]
43+
game_config.vibe_names = [vibe.name for vibe in game_config.actions.change_vibe.vibes]
4844

4945
# Set up resource mappings
5046
resource_names = list(game_config.resource_names)
@@ -56,8 +52,7 @@ def convert_to_cpp_game_config(mettagrid_config: dict | GameConfig):
5652

5753
# Set up vibe mappings from the change_vibe action config.
5854
# The C++ bindings expect dense uint8 identifiers, so keep a name->id lookup.
59-
num_vibes = game_config.actions.change_vibe.number_of_vibes
60-
supported_vibes = VIBES[:num_vibes]
55+
supported_vibes = game_config.actions.change_vibe.vibes
6156
vibe_name_to_id = {vibe.name: i for i, vibe in enumerate(supported_vibes)}
6257

6358
objects_cpp_params = {} # params for CppWallConfig
@@ -462,9 +457,8 @@ def process_action_config(action_name: str, action_config):
462457

463458
# Process change_vibe - always add to map
464459
action_params = process_action_config("change_vibe", actions_config.change_vibe)
465-
action_params["number_of_vibes"] = (
466-
actions_config.change_vibe.number_of_vibes if actions_config.change_vibe.enabled else 0
467-
)
460+
num_vibes = len(actions_config.change_vibe.vibes) if actions_config.change_vibe.enabled else 0
461+
action_params["number_of_vibes"] = num_vibes
468462
actions_cpp_params["change_vibe"] = CppChangeVibeActionConfig(**action_params)
469463

470464
game_cpp_params["actions"] = actions_cpp_params

packages/mettagrid/python/src/mettagrid/config/mettagrid_config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ class ChangeVibeActionConfig(ActionConfig):
195195
"""Change vibe action configuration."""
196196

197197
action_handler: str = Field(default="change_vibe")
198-
number_of_vibes: int = Field(default=0, ge=0, le=255)
198+
vibes: list[Vibe] = Field(default_factory=lambda: list(VIBES))
199199

200200
def _actions(self) -> list[Action]:
201-
return [self.ChangeVibe(vibe) for vibe in VIBES[: self.number_of_vibes]]
201+
return [self.ChangeVibe(vibe) for vibe in self.vibes]
202202

203203
def ChangeVibe(self, vibe: Vibe) -> Action:
204204
return Action(name=f"change_vibe_{vibe.name}")
@@ -459,8 +459,7 @@ class GameConfig(Config):
459459

460460
@model_validator(mode="after")
461461
def _compute_feature_ids(self) -> "GameConfig":
462-
self.actions.change_vibe.number_of_vibes = self.actions.change_vibe.number_of_vibes or len(VIBES)
463-
self.vibe_names = [vibe.name for vibe in VIBES[: self.actions.change_vibe.number_of_vibes]]
462+
self.vibe_names = [vibe.name for vibe in self.actions.change_vibe.vibes]
464463
return self
465464

466465
def id_map(self) -> "IdMap":
@@ -488,7 +487,7 @@ def EmptyRoom(
488487
) -> "MettaGridConfig":
489488
"""Create an empty room environment configuration."""
490489
map_builder = RandomMapBuilder.Config(agents=num_agents, width=width, height=height, border_width=border_width)
491-
actions = ActionsConfig(move=MoveActionConfig(), change_vibe=ChangeVibeActionConfig(number_of_vibes=len(VIBES)))
490+
actions = ActionsConfig(move=MoveActionConfig(), change_vibe=ChangeVibeActionConfig())
492491
objects = {}
493492
if border_width > 0 or with_walls:
494493
objects["wall"] = WallConfig(render_symbol="⬛")

packages/mettagrid/python/src/mettagrid/demo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def main():
6565

6666
# Enable change_vibe for GUI control, but create a policy config without it for random actions
6767
cfg.game.actions.change_vibe.enabled = True
68-
cfg.game.actions.change_vibe.number_of_vibes = 10
68+
from mettagrid.config.vibes import VIBES as ALL_VIBES
69+
70+
cfg.game.actions.change_vibe.vibes = list(ALL_VIBES[:10])
6971

7072
# Define objects used in the map
7173
cfg.game.objects = {

0 commit comments

Comments
 (0)