in procgen/src/games/chaser.cpp [140:258]
void game_reset() override {
int extra_orb_sign = 1;
if (options.distribution_mode == EasyMode) {
maze_dim = 11;
total_enemies = 3;
extra_orb_sign = 0;
} else if (options.distribution_mode == HardMode) {
maze_dim = 13;
total_enemies = 3;
extra_orb_sign = -1;
} else if (options.distribution_mode == ExtremeMode) {
maze_dim = 19;
total_enemies = 5;
extra_orb_sign = 1;
} else {
fassert(false);
}
if (maze_gen == nullptr) {
std::shared_ptr<MazeGen> _maze_gen(new MazeGen(&rand_gen, maze_dim));
maze_gen = _maze_gen;
}
BasicAbstractGame::game_reset();
options.center_agent = false;
agent->rx = .5;
agent->ry = .5;
eat_time = -1 * eat_timeout;
fill_elem(0, 0, main_width, main_height, MAZE_WALL);
maze_gen->generate_maze_no_dead_ends();
free_cells.clear();
std::vector<std::vector<int>> quadrants;
std::vector<int> orbs_for_quadrant;
int num_quadrants = 4;
int extra_quad = rand_gen.randn(num_quadrants);
for (int i = 0; i < num_quadrants; i++) {
std::vector<int> quadrant;
orbs_for_quadrant.push_back(1 + (i == extra_quad ? extra_orb_sign : 0));
quadrants.push_back(quadrant);
}
for (int i = 0; i < maze_dim; i++) {
for (int j = 0; j < maze_dim; j++) {
int obj = maze_gen->grid.get(i + MAZE_OFFSET, j + MAZE_OFFSET);
set_obj(i, j, obj == WALL_OBJ ? MAZE_WALL : obj);
if (obj == SPACE) {
int idx = j * maze_dim + i;
free_cells.push_back(idx);
int quad_idx = (i >= maze_dim / 2.0 ? 1 : 0) * 2 + (j >= maze_dim / 2.0 ? 1 : 0);
quadrants[quad_idx].push_back(idx);
}
}
}
for (int i = 0; i < num_quadrants; i++) {
int num_orbs = orbs_for_quadrant[i];
std::vector<int> quadrant = quadrants[i];
std::vector<int> selected_idxs = rand_gen.simple_choose((int)(quadrant.size()), num_orbs);
for (int j : selected_idxs) {
int cell = quadrant[j];
spawn_entity_at_idx(cell, 0.4f, LARGE_ORB);
set_obj(cell, MARKER);
}
}
free_cells = get_cells_with_type(SPACE);
std::vector<int> selected_idxs = rand_gen.simple_choose((int)(free_cells.size()), 1 + total_enemies);
int start_idx = selected_idxs[0];
int start = free_cells[start_idx];
agent->x = (start % maze_dim) + .5;
agent->y = (start / maze_dim) + .5;
for (int i = 0; i < total_enemies; i++) {
int cell = free_cells[selected_idxs[i + 1]];
set_obj(cell, MARKER);
spawn_egg(cell);
}
for (int cell : free_cells) {
set_obj(cell, ORB);
}
total_orbs = (int)(free_cells.size());
orbs_collected = 0;
std::vector<int> marker_cells = get_cells_with_type(MARKER);
for (int cell : marker_cells) {
set_obj(cell, SPACE);
}
free_cells.clear();
is_space_vec.clear();
for (int i = 0; i < grid_size; i++) {
bool is_space = get_obj(i) != MAZE_WALL;
if (is_space) {
free_cells.push_back(i);
}
is_space_vec.push_back(is_space);
}
}