Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/mettagrid/cpp/include/mettagrid/core/grid_object.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PACKAGES_METTAGRID_CPP_INCLUDE_METTAGRID_CORE_GRID_OBJECT_HPP_
#define PACKAGES_METTAGRID_CPP_INCLUDE_METTAGRID_CORE_GRID_OBJECT_HPP_

#include <climits>
#include <cstdint>
#include <optional>
#include <span>
Expand Down Expand Up @@ -153,8 +154,11 @@ class GridObject : public HasVibe {
aoe.unregister_effects();
}

virtual std::vector<PartialObservationToken> obs_features() const {
return {}; // Default: no observable features
// observer_agent_id: The agent observing this object (UINT_MAX means no specific observer)
// Used by Assembler to report agent-specific cooldowns
virtual std::vector<PartialObservationToken> obs_features(unsigned int observer_agent_id = UINT_MAX) const {
(void)observer_agent_id; // Unused in base class
return {}; // Default: no observable features
}

// Commons support
Expand Down
2 changes: 1 addition & 1 deletion packages/mettagrid/cpp/include/mettagrid/objects/agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Agent : public GridObject, public HasInventory, public Usable {
// Implementation of Usable interface
bool onUse(Agent& actor, ActionArg arg) override;

std::vector<PartialObservationToken> obs_features() const override;
std::vector<PartialObservationToken> obs_features(unsigned int observer_agent_id = UINT_MAX) const override;

// Set observation encoder for inventory feature ID lookup
void set_obs_encoder(const ObservationEncoder* encoder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ class Assembler : public GridObject, public Usable {
return true;
}

virtual std::vector<PartialObservationToken> obs_features() const override {
virtual std::vector<PartialObservationToken> obs_features(unsigned int observer_agent_id = UINT_MAX) const override {
(void)observer_agent_id; // Unused for assemblers
std::vector<PartialObservationToken> features;

unsigned int remaining = std::min(cooldown_remaining(), 255u);
Expand Down
3 changes: 2 additions & 1 deletion packages/mettagrid/cpp/include/mettagrid/objects/chest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class Chest : public GridObject, public Usable, public HasInventory {
return false;
}

virtual std::vector<PartialObservationToken> obs_features() const override {
virtual std::vector<PartialObservationToken> obs_features(unsigned int observer_agent_id = UINT_MAX) const override {
(void)observer_agent_id; // Unused for chests
if (!this->obs_encoder) {
throw std::runtime_error("Observation encoder not set for chest");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class CommonsChest : public Chest {
}

// Override obs_features to observe the commons inventory
virtual std::vector<PartialObservationToken> obs_features() const override {
virtual std::vector<PartialObservationToken> obs_features(unsigned int observer_agent_id = UINT_MAX) const override {
(void)observer_agent_id; // Unused for commons_chests
if (!this->obs_encoder) {
throw std::runtime_error("Observation encoder not set for commons_chest");
}
Expand Down
3 changes: 2 additions & 1 deletion packages/mettagrid/cpp/include/mettagrid/objects/wall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Wall : public GridObject {
GridObject::init(cfg.type_id, cfg.type_name, GridLocation(r, c), cfg.tag_ids, cfg.initial_vibe, cfg.aoe);
}

std::vector<PartialObservationToken> obs_features() const override {
std::vector<PartialObservationToken> obs_features(unsigned int observer_agent_id = UINT_MAX) const override {
(void)observer_agent_id; // Unused for walls
std::vector<PartialObservationToken> features;
features.reserve(1 + tag_ids.size() + (this->vibe != 0 ? 1 : 0));

Expand Down
3 changes: 2 additions & 1 deletion packages/mettagrid/cpp/src/mettagrid/objects/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ bool Agent::onUse(Agent& actor, ActionArg arg) {
return false;
}

std::vector<PartialObservationToken> Agent::obs_features() const {
std::vector<PartialObservationToken> Agent::obs_features(unsigned int observer_agent_id) const {
(void)observer_agent_id; // Unused for agents
if (!this->obs_encoder) {
throw std::runtime_error("Observation encoder not set for agent");
}
Expand Down
Loading