Skip to content

Commit 63c1c77

Browse files
authored
fix: SimulationAgent.inventory reads only from agent's own position (#4239)
The inventory property was iterating through ALL observation tokens (including other agents' inventories) instead of only looking at tokens at the center position where the agent sees itself.
1 parent b1afd11 commit 63c1c77

File tree

1 file changed

+7
-0
lines changed
  • packages/mettagrid/python/src/mettagrid/simulator

1 file changed

+7
-0
lines changed

packages/mettagrid/python/src/mettagrid/simulator/simulator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,14 @@ def inventory(self) -> Dict[str, int]:
377377
inv = {}
378378
obs = self.observation
379379

380+
# Agent's own tokens are at the center of the observation window
381+
c_sim = self._sim._c_sim
382+
center = (c_sim.obs_height // 2, c_sim.obs_width // 2)
383+
380384
for token in obs.tokens:
385+
# Only look at tokens at the agent's own position (center)
386+
if token.location != center:
387+
continue
381388
# Check if this is an inventory feature
382389
if token.feature.name.startswith("inv:"):
383390
# Extract resource name from "inv:resource_name" format

0 commit comments

Comments
 (0)