Skip to content

Commit dad4f76

Browse files
Always initialize SDC first (#259)
* Make SDC agent 0 and make sure it is always intialized and controlled * Oops little fix * Small fix: Make sure to increment num_actors. * Make SDC agent 0 and make sure it is always intialized and controlled * Oops little fix * Small fix: Make sure to increment num_actors. --------- Co-authored-by: Daphne Cornelisse <cor.daphne@gmail.com>
1 parent 84cf206 commit dad4f76

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

pufferlib/ocean/drive/drive.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ void set_active_agents(Drive *env) {
12611261
env->active_agent_count = 0; // Policy-controlled agents
12621262
env->static_agent_count = 0; // Non-moving background agents
12631263
env->expert_static_agent_count = 0; // Expert replay agents (non-controlled)
1264-
env->num_actors = 0; // Total agents created
1264+
env->num_actors = 1; // Total agents created (there is always the SDC)
12651265

12661266
int active_agent_indices[MAX_AGENTS];
12671267
int static_agent_indices[MAX_AGENTS];
@@ -1271,9 +1271,21 @@ void set_active_agents(Drive *env) {
12711271
env->num_agents = MAX_AGENTS;
12721272
}
12731273

1274+
// Create and initialize the SDC first to ensure we always have at least
1275+
// one controllable agent.
1276+
int sdc_index = env->sdc_track_index;
1277+
active_agent_indices[0] = sdc_index;
1278+
env->active_agent_count++;
1279+
env->entities[sdc_index].active_agent = 1;
1280+
12741281
// Iterate through entities to find agents to create and/or control
12751282
for (int i = 0; i < env->num_objects && env->num_actors < MAX_AGENTS; i++) {
12761283

1284+
// Skip if its the SDC
1285+
if (i == sdc_index) {
1286+
continue;
1287+
}
1288+
12771289
Entity *entity = &env->entities[i];
12781290

12791291
// Skip if not valid at initialization

0 commit comments

Comments
 (0)