in procgen/src/games/miner.cpp [247:314]
void game_step() override {
BasicAbstractGame::game_step();
if (action_vx > 0)
agent->is_reflected = false;
if (action_vx < 0)
agent->is_reflected = true;
handle_push();
int agent_obj = get_obj(int(agent->x), int(agent->y));
if (agent_obj == DIAMOND) {
step_data.reward += DIAMOND_REWARD;
}
if (agent_obj == DIRT || agent_obj == DIAMOND) {
set_obj(int(agent->x), int(agent->y), SPACE);
}
int main_area = main_width * main_height;
int diamonds_count = 0;
for (int idx = 0; idx < main_area; idx++) {
int obj = get_obj(idx);
int obj_x = idx % main_width;
int agent_idx = (agent->y - .5) * main_width + (agent->x - .5);
int stat_type = get_stationary_type(obj);
if (stat_type == DIAMOND) {
diamonds_count++;
}
if (obj == BOULDER || obj == MOVING_BOULDER || obj == DIAMOND || obj == MOVING_DIAMOND) {
int below_idx = idx - main_width;
int obj2 = get_obj(below_idx);
bool agent_is_below = agent_idx == below_idx;
if (obj2 == SPACE && !agent_is_below) {
set_obj(idx, SPACE);
set_obj(below_idx, get_moving_type(obj));
} else if (agent_is_below && is_moving(obj)) {
step_data.done = true;
} else if (is_round(obj2) && obj_x > 0 && is_free(idx - 1) && is_free(idx - main_width - 1)) {
set_obj(idx, SPACE);
set_obj(idx - 1, get_stationary_type(obj));
} else if (is_round(obj2) && obj_x < main_width - 1 && is_free(idx + 1) && is_free(idx - main_width + 1)) {
set_obj(idx, SPACE);
set_obj(idx + 1, stat_type);
} else {
set_obj(idx, stat_type);
}
}
}
diamonds_remaining = diamonds_count;
for (auto ent : entities) {
if (ent->type == ENEMY) {
if (rand_gen.randn(6) == 0) {
choose_new_vel(ent);
}
}
}
}