Skip to content

Commit 28bd91e

Browse files
committed
cp
1 parent 57f5cee commit 28bd91e

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

packages/mettagrid/cpp/include/mettagrid/objects/chest.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef PACKAGES_METTAGRID_CPP_INCLUDE_METTAGRID_OBJECTS_CHEST_HPP_
22
#define PACKAGES_METTAGRID_CPP_INCLUDE_METTAGRID_OBJECTS_CHEST_HPP_
33

4+
#include <algorithm>
45
#include <set>
56
#include <unordered_map>
67
#include <vector>
@@ -121,7 +122,8 @@ class Chest : public GridObject, public Usable, public HasInventory {
121122
throw std::runtime_error("Observation encoder not set for chest");
122123
}
123124
std::vector<PartialObservationToken> features;
124-
features.reserve(1 + this->inventory.get().size() + this->tag_ids.size() + 3);
125+
// Up to 2 tokens per inventory item (low byte + optional high byte)
126+
features.reserve(1 + this->inventory.get().size() * 2 + this->tag_ids.size() + (this->vibe != 0 ? 1 : 0));
125127

126128
if (this->vibe != 0) features.push_back({ObservationFeature::Vibe, static_cast<ObservationType>(this->vibe)});
127129

packages/mettagrid/cpp/include/mettagrid/objects/inventory.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef PACKAGES_METTAGRID_CPP_INCLUDE_METTAGRID_OBJECTS_INVENTORY_HPP_
22
#define PACKAGES_METTAGRID_CPP_INCLUDE_METTAGRID_OBJECTS_INVENTORY_HPP_
33

4+
#include <limits>
45
#include <string>
56
#include <unordered_map>
67
#include <vector>

packages/mettagrid/cpp/src/mettagrid/objects/agent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ std::vector<PartialObservationToken> Agent::obs_features() const {
209209
if (!this->obs_encoder) {
210210
throw std::runtime_error("Observation encoder not set for agent");
211211
}
212-
const size_t num_tokens = this->inventory.get().size() + this->tag_ids.size() + 5;
212+
const size_t num_tokens = this->inventory.get().size() * 2 + this->tag_ids.size() + 5;
213213

214214
std::vector<PartialObservationToken> features;
215215
features.reserve(num_tokens);

packages/mettagrid/docs/simulator_api.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,11 @@ obs = agent.observation
265265
for token in obs.tokens:
266266
if token.feature.name == "object_type":
267267
print(f"Object at ({token.col()}, {token.row()}): {token.value}")
268-
elif token.feature.name.startswith("inv:"):
269-
resource = token.feature.name[4:] # Remove "inv:" prefix
270-
print(f"Inventory {resource}: {token.value}")
268+
269+
# For inventory, use the agent.inventory property which handles the encoding
270+
inventory = agent.inventory
271+
for resource, amount in inventory.items():
272+
print(f"Inventory {resource}: {amount}")
271273
```
272274

273275
## Event Handling

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,7 @@ def convert_to_cpp_game_config(mettagrid_config: dict | GameConfig):
348348
if name in resource_name_to_id
349349
}
350350
limit_defs.append(
351-
CppLimitDef(
352-
resources=resource_ids, base_limit=min(resource_limit.limit, 255), modifiers=modifier_ids
353-
)
351+
CppLimitDef(resources=resource_ids, base_limit=resource_limit.limit, modifiers=modifier_ids)
354352
)
355353

356354
inventory_config = CppInventoryConfig()

0 commit comments

Comments
 (0)