min_max_path_general_brute_force = {
mode
let min_max_path = [];
let min_max_path_choices = [];
for (let y = 0; y < n; y++) {
let row = [];
let choice_row = [];
min_max_path.push(row);
min_max_path_choices.push(choice_row);
for (let x = 0; x < n; x++) {
row.push(null);
choice_row.push(null);
}
}
function* min_max_path_recursive(y, x) {
if (y < 0 || x < 0 || y >=n || x >= n) {
return 1;
} else if (x == 0 && y == 0) {
min_max_path[y][x] = grid[y][x];
} else {
let choice_values = [];
for(let i = 0; i < move_choices.length; i++) {
let choice = move_choices[i];
let yp = y + choice.dy;
let xp = x + choice.dx;
min_max_path_choices[y][x] = {'choice': i, 'confirmed': false};
yield Promises.delay(config.step_time, {values: min_max_path, choices: min_max_path_choices});
let choice_value = yield* min_max_path_recursive(yp, xp);
min_max_path_choices[y][x] = null;
choice_values.push(choice_value);
};
let minMaxPrev = Math.min(...choice_values);
let choice_index = choice_values.indexOf(minMaxPrev);
if (minMaxPrev < 1) {
min_max_path_choices[y][x] = {'choice': choice_index, 'confirmed': true};
}
min_max_path[y][x] = Math.max(grid[y][x], minMaxPrev);
}
yield Promises.delay(config.step_time, {values: min_max_path, choices: min_max_path_choices});
return min_max_path[y][x];
}
yield* min_max_path_recursive(n-1, n-1)
}