77 AgentConfig ,
88 AgentRewards ,
99 AttackActionConfig ,
10+ AttackOutcome ,
11+ ChangeVibeActionConfig ,
1012 GameConfig ,
1113 InventoryConfig ,
1214 MettaGridConfig ,
1719 WallConfig ,
1820)
1921from mettagrid .simulator import Simulation
20- from mettagrid .test_support .actions import attack , get_agent_position , move
22+ from mettagrid .test_support .actions import get_agent_position , move
2123from mettagrid .test_support .map_builders import ObjectNameMapBuilder
2224from mettagrid .test_support .orientation import Orientation
2325
2426
27+ def get_agent_frozen_status (sim : Simulation , agent_id : int ) -> bool :
28+ """Check if an agent is frozen."""
29+ grid_objects = sim .grid_objects ()
30+ for obj in grid_objects .values ():
31+ if obj .get ("agent_id" ) == agent_id :
32+ return obj .get ("is_frozen" , False )
33+ return False
34+
35+
2536@pytest .fixture
2637def base_config ():
2738 """Base configuration for swap tests."""
@@ -40,7 +51,12 @@ def base_config():
4051 "west" ,
4152 ]
4253 ),
43- attack = AttackActionConfig (enabled = True , consumed_resources = {"laser" : 1 }, defense_resources = {"armor" : 1 }),
54+ change_vibe = ChangeVibeActionConfig (number_of_vibes = 10 ),
55+ attack = AttackActionConfig (
56+ enabled = False , # Attack triggers via move, not standalone action
57+ vibes = ["charger" ], # Attack triggers when agent has charger vibe
58+ success = AttackOutcome (freeze = 10 ),
59+ ),
4460 ),
4561 objects = {
4662 "wall" : WallConfig (),
@@ -135,26 +151,35 @@ def test_swap_with_frozen_agent(make_sim, adjacent_agents_map):
135151 assert pos_agent0_before == (1 , 1 ), f"Agent 0 should be at (1, 1), got { pos_agent0_before } "
136152 assert pos_agent1_before == (1 , 2 ), f"Agent 1 should be at (1, 2), got { pos_agent1_before } "
137153
138- # Agent 0 attacks Agent 1 to freeze them
139- attack_result = attack (sim , target_arg = 0 , agent_idx = 0 )
140- print (f"Attack result: { attack_result } " )
141- assert attack_result ["success" ], f"Attack should succeed: { attack_result } "
154+ # Verify neither agent is frozen initially
155+ assert not get_agent_frozen_status (sim , 0 ), "Agent 0 should not start frozen"
156+ assert not get_agent_frozen_status (sim , 1 ), "Agent 1 should not start frozen"
142157
143- # Verify agent 1 is frozen
144- grid_objects = sim .grid_objects ()
145- agent1_obj = None
146- for _obj_id , obj in grid_objects .items ():
147- if obj ["type_name" ] == "agent" :
148- pos = (obj ["r" ], obj ["c" ])
149- if pos == pos_agent1_before :
150- agent1_obj = obj
151- break
152-
153- assert agent1_obj is not None , "Should find agent 1"
154- assert agent1_obj .get ("is_frozen" , False ), f"Agent 1 should be frozen: { agent1_obj } "
155- print (f"Agent 1 frozen status: { agent1_obj .get ('is_frozen' )} " )
156-
157- # Now agent 0 tries to move east onto frozen agent 1
158+ # Agent 0 changes vibe to charger (to enable attack on move)
159+ sim .agent (0 ).set_action ("change_vibe_charger" )
160+ sim .agent (1 ).set_action ("noop" )
161+ sim .step ()
162+
163+ # Agent 0 moves east into Agent 1 - should trigger attack due to weapon vibe
164+ sim .agent (0 ).set_action ("move_east" )
165+ sim .agent (1 ).set_action ("noop" )
166+ sim .step ()
167+
168+ # Verify agent 1 is frozen from the attack
169+ assert get_agent_frozen_status (sim , 1 ), "Agent 1 should be frozen after attack"
170+ print ("Agent 1 frozen status: True" )
171+
172+ # Verify positions didn't change on first move (attack happened but no swap yet)
173+ pos_agent0_mid = get_agent_position (sim , 0 )
174+ pos_agent1_mid = get_agent_position (sim , 1 )
175+ print (f"After attack - Agent 0: { pos_agent0_mid } , Agent 1: { pos_agent1_mid } " )
176+
177+ # Agent 0 changes vibe back to default so next move doesn't trigger attack
178+ sim .agent (0 ).set_action ("change_vibe_default" )
179+ sim .agent (1 ).set_action ("noop" )
180+ sim .step ()
181+
182+ # Now agent 0 tries to move east onto frozen agent 1 - should swap
158183 move_result = move (sim , Orientation .EAST , agent_idx = 0 )
159184 print (f"Move result: { move_result } " )
160185
0 commit comments