Skip to content

Instantly share code, notes, and snippets.

@MX-2000
Created March 26, 2025 10:56
Show Gist options
  • Save MX-2000/82816063f085312ddeb5912ec07626cf to your computer and use it in GitHub Desktop.
Save MX-2000/82816063f085312ddeb5912ec07626cf to your computer and use it in GitHub Desktop.
void compute_observations(CCpr *env) {
for (int i = 0; i < env->num_agents; i++) {
Agent *agent = &env->agents[i];
int obs_offset = i * env->obs_size;
int r_offset = agent->r - env->vision;
int c_offset = agent->c - env->vision;
for (int r = 0; r < 2 * env->vision + 1; r++) {
for (int c = 0; c < 2 * env->vision + 1; c++) {
int grid_idx = (r_offset + r) * env->width + c_offset + c;
int obs_idx = obs_offset + r * env->vision_window + c;
env->observations[obs_idx] = env->grid[grid_idx];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment